Android:httppostリクエストがプロキシを通過していないのはなぜですか?

StackOverflow https://stackoverflow.com/questions/5057623

  •  15-11-2019
  •  | 
  •  

質問

ここでの指示に従って、Fiddlerでトラフィックを見ることができるように、私のエミュレータに新しいアクセスポイントを設定しました。 http://aurir.wordpress.com/2010/03/22/010/03/22/010/03/22/tutorial-getting-android-emulator - Working-With-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;
}
.

私が間違っていることは何ですか?

役に立ちましたか?

解決

I have never tried this explicitly, but have seen many reports that redirecting emulator traffic by changing the APN only affects the Browser. You might have better luck running the emulator instance with the option -http-proxy <proxy>. Look here, under Emulator Startup Options (Network) for more:

http://developer.android.com/guide/developing/tools/emulator.html

$0.02: We use Charles to debug web services and booting up the emulator in this fashion works for all traffic.

Hope that helps!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top