Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 检索HttpPost的实体时出错_Android_Entity_Http Post_Httprequest - Fatal编程技术网

Android 检索HttpPost的实体时出错

Android 检索HttpPost的实体时出错,android,entity,http-post,httprequest,Android,Entity,Http Post,Httprequest,下面是我要发布的代码,然后从url获取响应。。。 无论何时运行代码,我都不会在Bufferedreader中得到响应 protected Void doInBackground(String... urls) { try{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.indianrail.gov.in/pnr_Enq.htm

下面是我要发布的代码,然后从url获取响应。。。 无论何时运行代码,我都不会在Bufferedreader中得到响应

protected Void doInBackground(String... urls) {

    try{

    HttpClient httpclient = new DefaultHttpClient();

    HttpPost httppost = new HttpPost("http://www.indianrail.gov.in/pnr_Enq.html");

    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

     response = httpclient.execute(httppost);

    }catch(Exception e){

    Log.e("log_tag", "Error in http connection "+e.toString());

    }

    return null;

    }


protected void onPostExecute(Void unused) {

    Dialog.dismiss();
    HttpEntity httpEntity= response.getEntity();
    Toast.makeText(getApplicationContext(), "resp of :"+response.getEntity().getContentLength(), Toast.LENGTH_SHORT).show();

    try {
        Toast.makeText(getApplicationContext(), "in", Toast.LENGTH_SHORT).show();
        Toast.makeText(getApplicationContext(), ""+response.getEntity().getContentLength(), Toast.LENGTH_SHORT).show();
        in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        Toast.makeText(getApplicationContext(), "string creating :)",Toast.LENGTH_SHORT).show();
       Toast.makeText(getApplicationContext(), ""+line, Toast.LENGTH_SHORT).show();
    }  catch (Exception e) {
        // TODO Auto-generated catch block
        Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_SHORT).show();

        e.printStackTrace();
    }
我在postExecute方法中的Bufferedreader处出错。。。 LogCat o/p如下所示

E/ActivityThread(611): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cf4cf0 that was originally bound here
请尝试以下操作:

如果您的响应是json,请按以下方式使用代码,然后使用
doInBackground(Void…params)
中实体的“响应”:


用错误回复您得到的结果。

在哪里声明响应?
DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(serviceURL);                                   
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();