0

POST メソッドを使用して、パラメータとして文字列とともにリクエストを Web サービスに送信しています。

例えば:-

HttpPost httpPost = new HttpPost(http://www.google.com/gmail/getpictures.php);//sample URL (not working)

Web サービスの URL とともに文字列も送信しています

tmp = new StringEntity(data,"UTF-8");//data is any string
tmp.setContentEncoding(new BasicHeader("Content-type", "application/json"));
httpPost.setEntity(tmp);

を使用してリクエストを送信します

response = httpClient.execute(httpPost);

サーバーに正しいデータを送信しているかどうかを確認するために、httpPost オブジェクトの内容を出力したいと考えています。 HttpPost.toString()が機能しません。LOGCATに出力できるように、 httpPost オブジェクトを文字列に取得する方法を知っている人はいますか?

4

3 に答える 3

1

応答からコンテンツを取得する必要があります。

InputStream inputstream = response.getEntity().getContent();
BufferedReader rd = new BufferedReader(new InputStreamReader(inputstream));

rdからデータを読み取ります。

于 2012-10-10T12:23:24.640 に答える
1

try this code

DefaultHttpClient hc = new DefaultHttpClient();
                                            ResponseHandler<String> res = new BasicResponseHandler();
String response = hc.execute(postMethod,res);
System.out.println(responce);
于 2012-10-10T12:24:59.947 に答える
1

これを試して

String response = httpclient.execute(httppost, responseHandler);
于 2012-10-10T15:18:56.593 に答える