Question

I've set up a new Access Point on my emulator so that I can view traffic in Fiddler by following the instructions here: http://aurir.wordpress.com/2010/03/22/tutorial-getting-android-emulator-working-with-fiddler-http-proxy-tool/

This works for the browser requests from the Emulator but the HttpPost request in my application is now visible in Fiddler.

Here's the code I'm using:

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;
}

Any idea what I'm doing wrong?

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top