android - Retrofit post request with parameters -
i using postman extension post request. want make same request android. used retrofit library access goal. can't successful result. mistake in code ?
my interface :
public interface interfacem { @formurlencoded @post("/login") call<responsebody> getresponse(@field("signin[username]") string username,@field("signin[password]")string password ); }
and retrofit usage :
retrofit retrofit = new retrofit.builder() .baseurl("http://myurl.com") .build(); interfacem service = retrofit.create(interfacem.class); call<responsebody> result =service.getresponse("myusername","mypassword"); result.enqueue(new callback<responsebody>() { @override public void onresponse(response<responsebody> response) { try { system.out.println(response.body().string().tostring()); } catch (ioexception|nullpointerexception e) { e.printstacktrace(); } } @override public void onfailure(throwable t) { t.printstacktrace(); } });
try provide body
public class signbody { @serializedname("signin[username]") @expose private string username; @serializedname("signin[password]") @expose private string password; }
change interface to
@post("/login") call<responsebody> getresponse(@body signbody body);
Comments
Post a Comment