Skip to content Skip to sidebar Skip to footer

Not Getting Response Response = Httpclient.execute(request);

public class HTTPPoster { public static HttpResponse doPost(String url, JSONObject c) throws ClientProtocolException, IOException { HttpClient httpclient = new De

Solution 1:

You should call the method asynchronously. Then it will work with the same code. Add these two lines of code to your project

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);

and make minimum sdk version to 9


Solution 2:

You can check that if you are getting response from server or not by using following code :

HttpResponse response = httpClient1.execute(request);
                    Log.v("response code", response.getStatusLine()
                            .getStatusCode() + ""); 

If you get the value of response code as 200 then you are getting data from server and if the response code value >=300 then you have error at your server side.


Solution 3:

First of all try to change the return type to String by doing these 2 steps

Change

public static HttpResponse doPost(String url, JSONObject c) throws ClientProtocolException, IOException 

to

public static String doPost(String url, JSONObject c) throws ClientProtocolException, IOException 

AND

Change

HttpResponse response; 

to

String response; 

Now check the response string? Is it still null?



Solution 4:

This is a permission issue.

Add this line <uses-permission android:name="android.permission.INTERNET" /> to your manifest file and rebuild.


Post a Comment for "Not Getting Response Response = Httpclient.execute(request);"