2011-09-12 49 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());