2011-09-12 7 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

を使用することができます。

res.getEntity().getContent() 

はあなたのInputStreamを返します。

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

あなたは私vvieuxの回答で、よりを追加してみましょうHttpEntity

res.getEntity().getContent()