Nearly all iPhone applications take advantage of the device’s amazing internet connectivity. Whether its checking the balance of your bank account or using an interactive web application in Safari, there is a tangible level of connectedness. Wouldn’t it be great if you could watch, log, and edit the HTTP requests live as they happen from the comfort of your desktop? Not only is it possible, it is easier than you might think and doesn’t require jailbreaking your device! This article shows you how in just a few easy steps.
May I take this opportunity to offer my highest recommendation for a wonderful piece of software called the Charles debugging proxy. The software allows you to view and edit HTTP requests that filter through its proxy server. It is secure, easy to install and configure, and runs on both Windows and OS X. Charles has become an essential tool in my web developer bag of tricks and I use it everyday.
You can download a free trial, but you won’t regret purchasing a license for only US $50.
</soapbox>
This tutorial will focus on connecting iPhone applications with the Charles debugger
PREREQUISITES
- A wireless LAN subnet to which your iPhone has access and is connected
- A laptop or desktop machine on the same LAN subnet as your iPhone
- Charles debugging proxy installed
There are two main areas of setup, the Charles proxy host, and the iPhone device.
PART 1 – CHARLES PROXY HOST SETUP
- Run Charles and verify that you have sufficiently enabled access through your system’s local firewall. Often this simply involves disabling the software firewall on your operating system. Charles needs to be listening on your LAN IP address and its default port is 8888. See your Operating System’s documentation for this specific procedure.
- Note your system’s IP address. In my case it is 10.45.200.127
PART 2 – IPHONE SETUP
- Download the charles SSL intermediate certificate
- Extract the charles.cer file from the zip archive.
At this point you have two ways you can install the charles.cer file on your device. You can either email it to yourself and open the attachment from the device. Or, you can post the file on a web server and request the certificate in Safari on the device. Either method will raise an Install prompt that looks like the one below:
- Configure your iPhone to use a proxy server
This step involves going to the Settings application and into the Wi-Fi section. There you will hopefully see an option for the Wireless AP name you are connected to.
Go to: Settings -> Wi-Fi -> “Your Wireless AP Name”
Once there, scroll to the bottom of the window and you should see settings options to configure a proxy host as below:
Enter your Charles proxy host address and port in the inputs provided
NOTE: Once you are done using the Proxy, you will have to set your HTTP Proxy setting to “Off” for your phone to return to normal function.
- Test the configuration
Open Safari and visit a website. You should see a prompt on your Charles machine to authorize the connection (this keeps unauthorized users from using your Proxy server):
Once the connection has been authorized, voilá! You should now see your phone’s HTTP requests live in Charles. For even more detail, you can click on the “Sequence” view.
Several useful things you can do with Charles at this point:
- Save file requests to disk by right clicking and choosing “Save Response…”
- Edit and resend HTTP requests by clicking the “Edit” icon on the toolbar with a request selected
- Debug SSL connections
- Throttle and simulate 3G network speeds in order to view how your app may respond. See “Throttle Settings” under the Proxy menu option.
Take a look at the Charles Documentation for other tips and tricks:
http://www.charlesproxy.com/documentation/using-charles/
Enjoy, and happy hacking!!