我已经在我的模拟器上设置了一个新的接入点,以便我可以按照以下说明查看 Fiddler 中的流量:http: //aurir.wordpress.com/2010/03/22/tutorial-getting-android-emulator-使用-fiddler-http-proxy-tool/
这适用于来自模拟器的浏览器请求,但我的应用程序中的 HttpPost 请求现在在 Fiddler 中可见。
这是我正在使用的代码:
private InputStream post(String url, Hashtable<String, String> postvariables) {
DefaultHttpClient httpClient = new DefaultHttpClient();
URI uri;
InputStream data = null;
try {
uri = new URI(url);
HttpPost method = new HttpPost(uri);
method.setHeader("Content-Type","application/json");
String param = new String();
Enumeration<String> e = postvariables.keys();
while(e.hasMoreElements())
{
String key = e.nextElement();
param = param + key + "=" + postvariables.get(key);
if(e.hasMoreElements()) {
param = param + "&";
}
}
Log.i("RestClient",url + param);
HttpEntity entity = new StringEntity(param);
method.setEntity(entity);
HttpResponse response = httpClient.execute(method);
data = response.getEntity().getContent();
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
知道我做错了什么吗?