2013-10-25 92 views
0

我正在研究一個應用程序並遇到此問題。我使用PHP作爲後端服務器和JSON作爲數據傳輸技術。但問題是,Http POST和RESPONSE不起作用。 Http GET正在工作,用戶正在登錄,但沒有響應回來,POST也無法正常工作。Android HTTPPost和HTTPResponse錯誤

如果您瞭解問題,請幫助我。

// Making HTTP request 
    try { 
     HttpParams httpParameters = new BasicHttpParams(); 
     HttpConnectionParams.setConnectionTimeout(httpParameters, timeOut);         HttpConnectionParams.setSoTimeout(httpParameters, timeOut);                  
     HttpClient httpClient = new DefaultHttpClient(httpParameters); 
     HttpEntity httpEntity = null; 
     HttpPost httpPost = new HttpPost(url); 
     httpPost.setEntity(new UrlEncodedFormEntity(params)); 
     HttpResponse httpResponse = httpClient.execute(httpPost); 
     httpEntity = httpResponse.getEntity(); 

}

+0

嘿,請具體談談您的問題。你能分享一下代碼片段嗎? – gokhanakkurt

+0

請發佈您迄今嘗試過的編碼。 – Ajeesh

+0

我正在使用JSONParser,代碼是正常的。 –

回答

0

嘗試這樣的:

HttpClient client = new DefaultHttpClient(); 
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit 
HttpResponse response; 

    try { 
     URI url = new URI("xxxxxxxxxxxxxxxxxxxxxx"); 
     HttpPost post = new HttpPost(url); 
     JSONObject json = new JSONObject(); 
     json.put("x",x); 
     json.put("y", y);   

     StringEntity se = new StringEntity(holder.toString()); 
     post.setEntity(se); 
     response = client.execute(post); 

     if(response!=null){ 
      InputStream in = response.getEntity().getContent(); //Get the data in the entity 
      in.close(); 
     } 
    } catch(Exception e) { 
     e.printStackTrace(); 
    }