Debugging Android Web Traffic

Normally, I would use a packet sniffer, such as WireShark (OS X and Windows) to look at the network traffic and debug the application.

However, for Android development I do my primary development on a physical Android device.  It is faster, and provides a more realistic experience during development and debugging.  However, since the network traffic is no longer going through my computer, WireShark doesn't help.

To solve this, I use another program called Charles.  Charles is a 'Web Debugging Proxy Application'.  In short, it is a tool similar to WireShark, that allows you to easily debug network traffic.  Charles is a bit 'higher level' than WireShark, and provides a simpler view of the web requests to developers.

It also has a great feature, called Reverse Proxy.  This allows you to setup your local computer as a proxy for web traffic.  You can set it up as follows:


If your normal Web Service host was targetwebserver.com:80, you would set it up like the image above.  You can then change your mobile application configuration to point at the IP address of your computer, using port 64829 (or whatever you set it to).

Note: Make sure your mobile devices is on the same WiFi network as your computer!

Now, all traffic will be routed through your local machine, and Charles will capture all the traffic, allowing you to debug your network communications.

Charles also supports HTTPS proxies, so you can use it even if the web services are over HTTPS (as they probably should be).

Of course, this also works fine for iOS, although I find myself using the simulator more in iOS, which allows WireShark or normal Charles to work fine.

Charles is commercial software, but I've found it to be worth the price.  I believe you could probably setup a reverse proxy on your computer using many different approaches (you could always run your own Apache), which would enable you to use the free WireShark application as well.

Does anyone have other approaches?

UPDATE:
And an intrepid reader (tehnoir) points out that you can also just use Charles as a 'normal' Proxy server, and then configure your device to use your computer as a proxy server, which will then proxy all traffic through.  This allows you to sniff traffic without changing anything in your application (great for testing).

It would seem that simple Port Forwarding (another Charles feature) may also work as well.