Alaways goin in onFailure in retrofit2.0 -


i trying hit api : www.xyz.com/abc_cc/cc/userregister/newuser

this code :

    public class mainactivity extends appcompatactivity {       public static final string base_url = "abc.com/abc_cc/cc/";      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          retrofit retrofit = new retrofit.builder()                 .baseurl(base_url) .client(getunsafeokhttpclient())                 .addconverterfactory(gsonconverterfactory.create())                 .build();          endpoints endpoints= retrofit.create(endpoints.class);         endpoints.newuser("{\"full_name\":\"sss\",\"states_id\":\"20\",\"mobile\":\"9876543210\",\"password\":\"******\",\"accept_terms\":true,\"userid\":\"0\",\"refer\":\"\",\"ip-address\":\"1.2.3.4\",\"device_type\":\"samsung j5\",\"os-version\":\"5.0.1\",\"client\":\"app\",\"secret_key\":\"44\"}")                 .enqueue(new retrofit2.callback<items>() {                     @override                     public void onresponse(retrofit2.call<items> call, retrofit2.response<items> response) {                         system.out.println("onresponse : "+response.message());                         system.out.println("onresponse : "+response.body());                         system.out.println("onresponse : "+response.code());                         system.out.println("onresponse : "+response.errorbody());                         system.out.println("onresponse : "+response.issuccessful());                         system.out.println("onresponse : "+response.raw());                         system.out.println("onresponse : "+response);                     }                      @override                     public void onfailure(retrofit2.call<items> call, throwable t) {                         system.out.println("onfailure"+call);                      }                 });       }      public static okhttpclient getunsafeokhttpclient() {          try {             // create trust manager not validate certificate chains             final trustmanager[] trustallcerts = new trustmanager[] { new x509trustmanager() {                 @override                 public void checkclienttrusted(                         java.security.cert.x509certificate[] chain,                         string authtype) throws certificateexception {                 }                  @override                 public void checkservertrusted(                         java.security.cert.x509certificate[] chain,                         string authtype) throws certificateexception {                 }                  @override                 public java.security.cert.x509certificate[] getacceptedissuers() {                     return new java.security.cert.x509certificate[0];                 }             } };              // install all-trusting trust manager             final sslcontext sslcontext = sslcontext.getinstance("tls");             sslcontext.init(null, trustallcerts,                     new java.security.securerandom());             // create ssl socket factory our all-trusting manager             final sslsocketfactory sslsocketfactory = sslcontext                     .getsocketfactory();              okhttpclient okhttpclient = new okhttpclient();             okhttpclient = okhttpclient.newbuilder()                     .sslsocketfactory(sslsocketfactory)                     .hostnameverifier(org.apache.http.conn.ssl.sslsocketfactory.allow_all_hostname_verifier).build();              return okhttpclient;         } catch (exception e) {             throw new runtimeexception(e);         }      }  } 

interface :

public interface endpoints {     @post("/userregister/newuser")     @formurlencoded     call<items> newuser(@field("data") string data);  } 

pojo class :

public class items {     @serializedname("response-status")     @expose     private boolean responsestatus;     @serializedname("response-validate")     @expose     private boolean responsevalidate;     @serializedname("response-message")     @expose     private string responsemessage;     @serializedname("response-data")     @expose     private responsedata responsedata;      public boolean getresponsestatus() {         return responsestatus;     }      public void setresponsestatus(boolean responsestatus) {         this.responsestatus = responsestatus;     }      public boolean getresponsevalidate() {         return responsevalidate;     }      public void setresponsevalidate(boolean responsevalidate) {         this.responsevalidate = responsevalidate;     }      public string getresponsemessage() {         return responsemessage;     }      public void setresponsemessage(string responsemessage) {         this.responsemessage = responsemessage;     }      public responsedata getresponsedata() {         return responsedata;     }      public void setresponsedata(responsedata responsedata) {         this.responsedata = responsedata;     }  } 

i getting response :

{protocol=http/1.1, code=404, message=not found, url=www.xyz.com/userregister/newuser} 

i have given proper url why taking half of it?

i have tried example https://code.tutsplus.com/tutorials/sending-data-with-retrofit-2-http-client-for-android--cms-27845. example , link given in example working fine, if same url above error

i hope kindly check parsing issues may occurred.

 @override public void onfailure(retrofit2.call<items> call, throwable t) {  system.out.println("onfailure"+call); 

//add lije got exceptions.

 t.printstacktrace();  } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -