Hey Folks! Today we are up to some sniffing on Android, great! … What for? Well, if you develop Cloud-related Apps, I mean by that an App that is going to use a REST Web API, then sooner or later you may want to observe the http traffic on your device for debugging purposes.
Telerik provides that great freeware named Fiddler, a powerful web debugger that can, among other things, log the http traffic. Basically Fiddler runs on Windows and can be used to debug a desktop App performing web requests. We are going to see how Fiddler can be used to also watch web requests performed from an Android device.
If you search for the topic on the web, you will find many resources, blog posts and questions about it, that’s what I did. However in most of them the information was just partial and I had to struggle a bit to get it working on my side, so I decided to produce my own post on the topic.
Prerequisites:
- A Windows machine (physical or virtual)
- An Android device
- A Wi-Fi connection
I – Observing HTTP Traffic from the Android device
You need to install Fiddler from the link below on your Windows machine. Start the program and go to Tools –> Fiddler Options …
On the HTTPS Tab, check the Decrypt HTTPS traffic, you will have to install a certificate for that and restart Fiddler
On the Connections Tab then, make sure the Allow remote computers to connect is checked.
Set a port for Fiddler, by default 8888 is set up, you can leave it like that - or change it to something else if you are anti-conformist.
Now check what IP address Fiddler and your Windows machine are running on: you can simply hover over Fiddler upper-right corner Online icon:
On the Android device now:
Make sure the device is connected to the same Wi-Fi network than your Windows machine.
Go to Settings –> Wi-Fi –> Long press on the connected network (usually the first one in the list) –> Modify Network
This should bring an option dialog, scroll down and check “Show advanced options”
This lets you set the “PROXY SETTINGS” to “Manual”
Then set PROXY HOSTNAME = the IP address from above (192.168.1.110) and PROXY PORT = the Fiddler port you use (8888)
Save and fire a browser on your device, you should now see the web requests logged in Fiddler. However this is not enough to log requests from an App on the device, you will need to install a certificate on Android now:
In the browser type the following url (of course update with your own values):
http://192.168.1.110:8888/FiddlerRoot.cer
You should see a dialog prompting your to install the certificate, I use a fancy name: “Fiddler”
And that should be it …You can now see http traffic from your App in Fiddler:
II – Observing HTTP Traffic from the Android Emulator
What if you don’t have an Android device between your hands? No worries, you can get that done from the emulator as well.
The set up on Windows is the same, just start your Android emulator, you can do that from Eclipse, Android Studio or the command line “emulator –avd virtual_device_name”
Once the emulator is running do the following:
Settings –> Wireless controls –> Mobile Networks –> Access Point Names (there should be one by default) –> click the APN to configure it
Set the Proxy and Port fields as previously with your IP and Fiddler port. Navigate back to home screen, fire up a browser and do the certificate thing like before.
Fiddler should now log the traffic of your device and having installed the certificate, your web App should be fully ready to be debugged…
Comments
You can follow this conversation by subscribing to the comment feed for this post.