我使用POST方法将一个请求连同一个字符串一起作为参数发送给一个web服务。如何从HttpPost对象读取数据?
例如: -
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()不适合我。任何人都知道如何将httpPost对象转换为字符串,以便我可以在LOGCAT上打印它?
问题是有点奇怪。您正在数据对象中发送JSON数据。你到底想看什么?格式化发送到服务器的请求? –
雅这很奇怪。实际上,我正在将SQL查询作为字符串连同其URL一起发送到服务器。但我得到的答复是失败的。所以我想看到的是我是否以正确的方式发送查询?所以我想看到它在logcat之前响应= httpClient.execute(httpPost); – Ani
好的。问题是你的字符串包含空间。 http://www.androidhive.info/2011/10/android-making-http-requests/这会帮助你。 –