When i call any webService with expired token,the service returns code 498 with error message "your tokken is expired"..BUT the retrofit gives the response code 500 with error message " internel server error".
response.code() //500 instead of 498
I tested the same url with postman and its working fine but the issue is only with retrofit.
I am using same services on IOS with AFNetworking and its also working fine there.
Any body can help to figure out why this is happening? thanks in advance.
This is not a full answer, but it's too big for a comment.
5xx codes are server errors, this means that the server is crashing, not the app nor is retrofit buggy. The issue most likely is in the server, but can be caused by retrofit - yes, that's true.
My experience with all the questions that say: "I tried this insert random network call here with postman and it works, but retrofit returns 500" is because postman adds headers by default, which retrofit doesn't. The server implementation then expects these headers to be set and due to a faulty implementation crashes if said headers are missing.
I would check the headers retrofit is sending and the headers postman is sending and compare both and make sure which one crashes the server.
It can also be that OkHttp (Retrofit uses OkHttp under the hood) is adding some headers which the server cannot cope with. This would be stranger to me, but not impossible. I think it adds for example by default gzip and some servers might not handle this correctly.
If you have access to the server, than it might even be worth checking there the logs. They might point you right away to the issue.
I'm sorry but I cannot point you directly to the problem. These are just tips to get you started. Hope they help.
Related
All the API's work in the browser but none of them is working in my android app and postman.
Status:
In postman and in my app, error code received is:
500 Internal Server Error
I think your problem is csrf-token you can disabled it in
App\Http\Middleware\VerifyCsrfToken
and add your routes name in this array
$except = [] array.
It could be that postman is missing some request headers, cookies or session data. You could look into using Postman Interceptor. It's a tool which records requests made from Google Chrome and clones them to your Postman history. From that history tab you can simply replay the request, which will be an exact clone. Maybe that'll resolve the 500 errors you're getting.
TLDR: Is there a way to force OkHttp to correctly handle unexpected/unrequested 100 Continue HTTP responses?
I'm using OkHttp 3.8.1 on Android to POST to a poorly-behaved server.
Even though the request does not include an "Expect: 100-continue" header, the web server returns a 100 Continue response. Rather than continuing to send the request body, then getting the actual (200) response, OkHttp stops there and sends back the 100 Continue response in my okhttp.Callback.
I tried explicitly including "Expect: 100-continue" in the request to trigger OkHttp's logic, but the server (possibly due to some bug) claims the header is malformed and rejects the request. I also tried sending "Expect:" (no value), but the server still sends the 100 Continue response and OkHttp stops there.
Other HTTP clients (I've tested 3 so far) can talk to that server just fine. They handle the 100 Continue response correctly even though they didn't see "Expect: 100-continue" in the request header. Is there an option I can set, or an interceptor I can write, to make OkHttp do the same?
Sounds like something we can fix in OkHttp. This is weird and the server is broken, but if other clients handle it OkHttp should too.
Please report a bug there?
I am using asp.net webapi v2 to create a rest api, everything is OK ! the GET request handled well, but I have a problem with POST request. I write a POST method in the Controller, and can call it using Postman. But when I try to call POST request with retrofit in my android app, it fails and get me this error : 405 Method Not Allowed.
It seems that every thing is okey but I don't know whats the problem !
this is my retrofit rest service :
#FormUrlEncoded
#POST("/Report")
void sendReport(#Field("UniqueID") String UniqueID, #Field("ShopID") long ShopID, #Field("Content") String Content, Callback<Boolean> callback);
I should mention that I've return bool in my POST action ! can it cause the problem because of Boolean in the retrofit ?!
what should I do now ?
Finally I found the solution, but I don't know why this happened !
The problem was the URL endpoint, It seems that POST method in webapi are case sensitive and I should use report against Report !!! (That was not happen in GET cases)
Another problem was the www prefix ! when I remove that it works like a charm but again it doesn't matter in GET cases !!!
I post this answer to help someone with the similar case ... hope so.
I am making a POST call to a tomcat server running Struts2 using the retrofit library on an Android Galaxy S3 (/Nexus 7) device. The POST call fails. The tomcat log shows Socket timeout exception.
The same POST using the exact same headers done via curl does not have any issues. I verified that the data on the wire matches using charles proxy.
Any tips/ideas on debugging this issue.
The post call is as follows
#POST(Constants.URL_GET_ORDER_LIST_BASE)
void getCardOrderList(#Body GetOrderListRequest getOrderListRequest, Callback<GetOrderListResponse> cbGetOrderListResponse);
Please let me know if I need to add more information to explain this better.
Adding Square's OKHTTP library into the libs folder fixed the issue.
I was having SocketTimeoutExceptions too. Pay attention to always add the final slash to your POST call.
Example:
BAD
#POST("/customers")
GOOD
#POST("/customers/")
My mistake was just this :)
I am currently using the DefaultHttpClient to create an HTTP request to a rails server.
The network call is failing about 4% of the time with a SocketTimeoutException.
I have run Wireshark on my network traffic and discovered the following:
My successful call starts like this
And ends like this
The failed call starts like this:
And ends like this
Please note that the HTTP OK message that is sent to us from the server is missing from the end call, resulting in it timing out after about 15 seconds.
I am wondering if anybody has encountered this before or has any recommendations for debugging the Android Apache library or Apache rails to figure out why we are not receiving the HTTP OK message from the server.
I figured this out. The rails server and apache library were timing out if there were bad parameters in my post request. We were passing in a "_b" parameter, and for some unknown reason the server wouldn't like this and would time out the request. Removing the bad post parameter fixed the problem.
If anybody else is seeing timeouts like this, I recommend reviewing the POST parameters that are being passed in.