以下のコードには、フィドラーがAVDエミュレーターで行われている投稿を確認できない問題を解決するために提案された2行が含まれています。2行がなければ、投稿は成功しますが、フィドラーはそれを見ることができません。2行の場合、I / O例外を除いて、約10分後に投稿が返されます。
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;