2011-09-12 52 views
1

我想發送JSON到我的服務器,並作爲結果檢索返回的JSON。 就像發送用戶名和密碼並取回令牌和其他內容一樣。Android HTTPRequest週期

這就是我正在做的HTTP請求發送。我現在如何檢索相同請求中的內容?

 HttpClient client = new DefaultHttpClient(); 

     HttpPost request = new HttpPost("http://192.168.1.5/temp/test.php"); 

     List<NameValuePair> value = new ArrayList<NameValuePair>(); 

     value.add(new BasicNameValuePair("Name", jsonStr)); 

     UrlEncodedFormEntity entity = new UrlEncodedFormEntity(value); 

     request.setEntity(entity); 

     HttpResponse res = client.execute(request); 

     String[] status_String=res.getStatusLine().toString().trim().split(" "); 
     //String hd=res.getFirstHeader("result").toString(); 

     //System.out.println("Res=" + res); 
     Log.e("tag", ""+res.toString()); 
     if(status_String[1].equals("200")){ 
      isDataSent=true; 

回答

1

讓我vvieux的回答增添更多:

res.getEntity().getContent() 

將返回的InputStream。

1
String returnData = EntityUtils.toString(res.getEntity());