0

I am Using Loopj library to parse json data in my android application but every time response goes in onFailure.

W/JsonHttpRH: onFailure(int, Header[], String, Throwable) was not overriden, but callback was received W/JsonHttpRH: org.apache.http.client.HttpResponseException: Method Not Allowed W/JsonHttpRH: at com.loopj.android.http.AsyncHttpResponseHandler.sendResponseMessage(AsyncHttpResponseHandler.java:466) W/JsonHttpRH: at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:160) W/JsonHttpRH: at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:177) W/JsonHttpRH: at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:106) W/JsonHttpRH: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442) W/JsonHttpRH: at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) W/JsonHttpRH: at java.util.concurrent.FutureTask.run(FutureTask.java:137) W/JsonHttpRH: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) W/JsonHttpRH: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) W/JsonHttpRH: at java.lang.Thread.run(Thread.java:856) E/CT: E/CT: E/CT: E/CT: E/CT:
Service

Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96
Pratik Sule
  • 163
  • 4
  • 18

3 Answers3

0

I think problem is in your URL Putting a '/' at the end of URL causes the redirect to happen because your server likes URLs that end in '/'. POST is fully supported by the URL your server redirects you to, but the client is executing a GET request when it behaves according to your setRedirecting() call (cURL does the same exact thing with the -L switch) The fix is to either put a '/' at the end of URL, or to grab the Location header from the response yourself and then initiate another POST request manually.

This can be observed in wireshark. You can test the theory by trying to perform a GET request with your browser to the URL with a slash appended to it. That will cause the browser to get a 405. Here's the fixed code for Android, this code uses the simple fix of appending a '/' to the URL (not production ready):

or

you forgot to allow your app to access the internet in the manifest. As for the documentation not matching my code's callbacks, the versions may not match because the signatures in the source of my android async 1.4.3 jar are consistent with my overrides.

sud
  • 505
  • 1
  • 4
  • 12
  • I am hitting two different links in first response goes to success and i get data in app but in second response goes to onFailure – Pratik Sule Oct 17 '15 at 07:23
0

First you check json data i.e coming data is in jsonArray format or only array type. use this method for parse json data

private void parseJSON() {

    try {
        JSONObject josn = new JSONObject(GetCar);

                    JSONArray array = json.getJSONArray("Company");

    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Binesh Kumar
  • 2,763
  • 1
  • 16
  • 23
0
Method Not Allowed 

You are trying to make HTTP call with method(POST, PUT) that is not allowed on your server side.

Orest Savchak
  • 4,529
  • 1
  • 18
  • 27
  • sorry i did not get you properly.. will you explain me? actually i am new in android – Pratik Sule Oct 17 '15 at 09:02
  • Thanks a lot Orest.. I got it. It was really silly mistake by me. I have send you friend request also on fb. – Pratik Sule Oct 17 '15 at 11:31
  • It is not Android feature, it is simple http communication theory. But maybe there is some other problems, but logger said that you do wrong http method. If it is correct answer, you can any time mark it as correct:) – Orest Savchak Oct 17 '15 at 11:35