2013-03-04 52 views
0

以下實體是我的代碼後,然後您可以通過網址... 每當我運行的代碼我沒有得到的BufferedReader響應...錯誤檢索的HttpPost

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 [email protected]f4cf0 that was originally bound here 
+0

哪裏迴應聲明? – 2013-03-04 11:53:50

回答

0

嘗試以下操作:

使用你的代碼在弗洛如果你的反應是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(); 

回覆錯誤你是什麼結果你..