【问题标题】:Error in retrieving entity of HttpPost检索 HttpPost 实体时出错
【发布时间】:2013-03-04 11:39:16
【问题描述】:

以下是我发布的代码,然后从 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

【问题讨论】:

  • 响应声明在哪里?

标签: android entity http-post httprequest


【解决方案1】:

尝试以下方法:

如果您的响应是 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();

用错误回复你得到的结果..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-19
    • 2017-01-24
    • 1970-01-01
    • 2019-12-06
    • 2015-01-25
    • 2017-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多