not getting response response = httpclient.execute(request);

只谈情不闲聊 提交于 2019-12-01 11:19:37

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

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.

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?


This is a permission issue.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!