java - Get raw HTTP response with Retrofit -


i want raw http response api rest. have tried interface:

@post("/login") @formurlencoded call<retrofit.response> login(@field("username") string login, @field("password") string pass,                      @field("appname") string appname, @field("appkey") string appkey); 

but get:

java.lang.illegalargumentexception: unable create call adapter retrofit.call method api.login

i create retrofit way:

retrofit.builder retrofitbuilder = new retrofit.builder(); retrofitbuilder.addconverterfactory(jacksonconverterfactory.create()); retrofit retrofitadapter = retrofitbuilder.baseurl(baseurl).build(); return retrofitadapter.create(apiclass); 

to access raw response, use responsebody okhttp call type.

call<responsebody> login(...) 

in callback, can check response code code method of response. applies retrofit 2 return type, because callback gets response parameterized actual return type. asynchronous --

call<responsebody> mycall = myapi.login(...) mycall.enqueue(new callback<responsebody>() {     @override     public void onresponse(response<responsebody> response, retrofit retrofit) {         // access response code response.code()         // access string of response response.body().string()     }      @override     public void onfailure(throwable t) {         t.printstacktrace();     } }); 

for synchronous calls --

response<responsebody> response = mycall.execute(); system.out.println("response code" + response.code()); 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -