Hi,
I am getting response code as 200 OK but even after that onFailure() method gets called
Probably because the converter threw an exception. If this is a Retrofit bug please provide a test case or executable code that demonstrates the issue. But if it's just a disagreement between your converter and the data on the wire then that's an application problem that you ned to fix.
It was working fine in retrofit2.0.0-beta2 but when I upgraded it to retrofit2.0.0-beta3 it is giving this error message
End of input at line 1 column 1
Please see the logs for more
01-07 11:13:55.390 12462-14915/in.qikstay.app D/OkHttp: --> END POST (109-byte body)
01-07 11:13:56.301 12462-14915/in.qikstay.app D/OkHttp: <-- 200 OK https://someurl (910ms)
01-07 11:13:56.301 12462-14915/in.qikstay.app D/OkHttp: Cache-Control: no-cache
01-07 11:13:56.301 12462-14915/in.qikstay.app D/OkHttp: Pragma: no-cache
01-07 11:13:56.301 12462-14915/in.qikstay.app D/OkHttp: Content-Length: 0
01-07 11:13:56.301 12462-14915/in.qikstay.app D/OkHttp: Expires: -1
01-07 11:13:56.301 12462-14915/in.qikstay.app D/OkHttp: Server: Microsoft-IIS/8.0
01-07 11:13:56.301 12462-14915/in.qikstay.app D/OkHttp: X-AspNet-Version: 4.0.30319
01-07 11:13:56.301 12462-14915/in.qikstay.app D/OkHttp: X-Powered-By: ASP.NET
01-07 11:13:56.301 12462-14915/in.qikstay.app D/OkHttp: Date: Thu, 07 Jan 2016 05:43:54 GMT
01-07 11:13:56.301 12462-14915/in.qikstay.app D/OkHttp: OkHttp-Sent-Millis: 1452145436174
01-07 11:13:56.302 12462-14915/in.qikstay.app D/OkHttp: OkHttp-Received-Millis: 1452145436300
01-07 11:13:56.302 12462-14915/in.qikstay.app D/OkHttp: <-- END HTTP (0-byte body)
01-07 11:13:56.342 12462-12462/in.qikstay.app V/error: End of input at line 1 column 1
The response body is empty but you are asking Gson to deserialize it as some type. This is the disagreement between the response data and what you are asking the converter to deserialize. For API calls that return no response you can use Call<Void>.
Thank you so much JakeWharton, you saved my day. Its working fine now :)
Hello @JakeWharton what happens if I do not expect a < Void > callback. I could get a 500 error or a 401 with no response. 401 means unauthorized, so i will prompt a user to re-enter their credentials. How do I check the status code in onFailure()?
Failure is only called when there is no response or the response cannot be parsed as a result of programmer error (either on client or server side). So that case would never happen.
The header will have a 401 status code but no response, or a single string "Unauthorized". If its just single string, I guess I could accept non json in my converter...
Ahh nvm. i got it, i just forced a 400 and got the status code in onResponse. Thanks
Hello I am doing a POST request my Request return status of 200 OK and I do that
`
Retrofit retrofit = new Retrofit.Builder()
//.baseUrl("https://polybookshare.com/")
.baseUrl("http://10.0.2.2:8080")
.client( trustTestClient.build())
//.addConverterFactory(GsonConverterFactory.create())
.build();
poly = retrofit.create(PolyBookShareAPI.class);
final Call
login.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
Log.d("response", response.message());
}
@Override
public void onFailure(Call<User> call, Throwable t) {
Log.d("fail", t.getMessage());
}
});`
But on Response does not return anything it calls onFailure End of input at line 1 column It does not make sense
Call
BASE_URL = "http://cartymetro.tk/api/
Gson gson = new GsonBuilder().setLenient().create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
@Headers({ rawResponse:Response{protocol=http/1.1, code=200, message=OK, url=http://cartymetro.tk/api/register} Please help from past 2days facing problem.
"Accept: application/json",
"Content-Type: application/json"
})
@FormUrlEncoded
@POST("register")
Call
///response
body:
for get request its working fine.
API returning back 200 status, but still, retrofit calls onFailure only
Most helpful comment
The response body is empty but you are asking Gson to deserialize it as some type. This is the disagreement between the response data and what you are asking the converter to deserialize. For API calls that return no response you can use
Call<Void>.