下面的代码有两行建议用于解决提琴手在 AVD 模拟器中看不到帖子的问题。没有这两行,帖子就成功了,但提琴手看不到它。对于这两行,帖子在大约 10 分钟后返回,但出现 I/O 异常。
public HttpResponse postData()
{
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/api/GETTrafficDirector");
HttpResponse response = null;
//do these two lines so fiddler can see post when debugging
HttpHost proxy = new HttpHost("192.168.2.8", 8888);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
response = httpclient.execute(httppost);
}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
}
catch (IOException e)
{
// TODO Auto-generated catch block
}
return response;