What exactly do Volley "response" and "error" contain? - android

I can't really understand this concept . My knowledge on webservices and oop is limited. Lets say that I set up a string request and pass a very simple database connection php script url to it. What would the volley response and error contain?

Volley follows standard [HTTP response codes][1].
[1]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html .
When the server responds with a HTTP OK - 200 Code it goes through the onResponse Callback . For all error code it would go through the onError Callback.

Related

Retrofit incorrect response error on android

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.

asp.net post action error on retrofit calling but okey on manual calling

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.

HTTP GET url with Json parameters in Android

I am having the following API call:
http://rollout.gr/api/?query={%22search%22:%22places%22,%22page%22:1}
This API call is executed correctly in my browser. But when I use a DefaultHttpClient to execute this url in my Android application, I get a null response.
I suppose the problem is the JSON data in the HTTP url. Thus, I would like to ask which is the proper way to handle such url in an Android application?
Thanks a lot in advance!
The accolades aren't valid URL characters. The browser is userfriendly enough to automatically URL-encode them, but DefaultHttpClient isn't. The correct line to use from code is:
http://rollout.gr/api/?query=http://rollout.gr/api/?query=%7b%22search%22:%22places%22,%22page%22:1%7d
Note the encoding for the accolades (%7b, %7d).
Your problem may be the strictmode here.
I recommend to do http request in threads or asynctasks. strictmode doesnt let app do http reauest in uithread. maybe your console shows a warning and you get null from http response because of this.
This project may solve your problem:
http://loopj.com/android-async-http/
Not knowing your particular HTTP initialization code, I'm going to assume you didn't provide an explicit JSON accept header. A lot of REST endpoints require this.
httpget.setHeader("Accept", "application/json");

Playing with Android Http Request and Response

I made a test project just testing http request and response behavior, There is a simple http class extending Asynctask to make request and get response. I am performing some string manipulation on http response, there is a problem my code which is using http response is executing before getting the response from class, which results null pointer exception. So to resolve this i made a thread and all code dependent on http response put in that thread. Now every thing is working fine.But i want to know is there any other technique to handle this? or my approach is good? Please suggest.
i want to know is there any other technique to handle this?
Use AsyncTask for Android Http Request.

Android HTTP Post request problem

I'm working on an issue which is:
+ I send a HTTP POST request to a server and get the response.
+ I use a DefaultHTTPClient instance to send the request. And I use BasicNameValuePair to add the params for the server to process.
There is a param which is a xml-based string. The problem is that, when I send an "empty" string like this: " ", the server response "SUCCESSFUL". But when I send another value which is much longer. The server response "UNSUCCESSFUL" due to this parameter.
Please tell me that whether Android has a max length limitation on BasicNameValue instance or not? And how can I fix this issue.
Thanks in advance.
I expect the problem is with your web service, not with the BasicNameValue implementation on Android: you are probably just sending it a bad parameter. Do you get SUCCESSFUL when you send the exact same request parameters from another programming language?

Categories

Resources