iOS Development Tools-Network packet analysis tools Charles

Source: Internet
Author: User
Tags ssl certificate

Brief introduction

This article is for Infoq Chinese Station Special manuscript, the starting address is: article link. If you want to reprint, please contact Infoq Chinese Station.

Charles is a common tool for intercepting network packets under Mac, and in iOS development, we often need to intercept network packets for debugging and server-side network communication protocols. By setting himself up as a network Access Proxy for the system, Charles enables all network access requests to be done through it, enabling the interception and analysis of network packets.

Charles is a freeware and can be used for a free 30-day trial. After the trial period, unpaid users can still continue to use, but each use time can not exceed 30 minutes, and start with a 10-second delay.

Therefore, the payment scheme is very user-friendly, even if you do not pay for a long time, you can use the full software features. Just when you need to do the package debugging for a long time, it will be affected by Charles ' forced shutdown.

Charles ' main features include:

    1. Support SSL Proxy. You can intercept requests that analyze SSL.

    2. Supports flow control. You can simulate slow networks and long wait times (latency) of requests.

    3. Supports Ajax debugging. JSON or XML data can be automatically formatted for easy viewing.

    4. Supports AMF debugging. The flash Remoting or Flex Remoting information can be formatted for easy viewing.

    5. Support to re-send network requests, convenient back-end debugging.

    6. Support for modifying network request parameters.

    7. Supports interception and dynamic modification of network requests.

    8. Check whether Html,css and RSS content meet the standards.

Install Charles

Go to Charles's official website (http://www.charlesproxy.com) to download the latest version of the Charles installation package, which is a dmg suffix file. When opened, drag Charles to the application directory to complete the installation.

Installing an SSL Certificate

If you need to intercept the analysis of the SSL protocol related content. Then you need to install Charles's CA certificate. The steps are as follows:

    1. Go to Http://www.charlesproxy.com/ssl.zip to download the CA certificate file.

    2. After extracting the zip file, double-click the. crt file in it, and then select "Always Trust" in the pop-up menu as follows:

    3. You can see the certificate that was added successfully from the Keychain access. As shown below:

Set Charles as a system agent

As mentioned earlier, Charles was intercepted by setting himself up as a proxy server, so the first step to using Charles was to set it up as a proxy server for the system.

When Charles is started, Charles will ask you to set permissions on the System agent for the first time. You can enter the login password to grant Charles this permission. You can also ignore the request and then, when you need to set up Charles as a system agent, choose "Proxy" –> "Mac OS X Proxy" in the menu to set Charles as the System agent. As shown below:

After that, you can see a steady stream of Web requests appearing in Charles's interface.

Introduction to Charles Main interface

Charles provides 2 views of the package, named "Structure" and "Sequence", respectively.

    1. The structure view classifies network requests by the domain name that is accessed.

    2. The sequence view sorts network requests by the time they are accessed.

You can switch back and forth between the two views according to your specific needs.

For a specific network request, you can view its detailed request content and response content. If the response is in JSON format, Charles can automatically format the JSON content for you to see.

Filtering Network Requests

    1. in Charles's menu bar, select "Proxy" –> "Recording Settings", then select the Include column, select Add an item, then fill in the protocol, host address, port number you want to monitor. This allows you to intercept only the packets of the target Web site. As shown:

Typically, we use Method 1 to do some temporary packet filtering, using method 2 to do some frequent packet filtering.

Intercept network packets on your iphone

Charles is often used to intercept local network packets, but we can also use them to intercept network requests on other devices when we need them. I'll take the iphone as an example to explain how to do it.

The settings on Charles

To intercept the network request on the iphone, we first need to turn on Charles's proxy function. In Charles's menu bar, select "Proxy", "Proxy Settings", fill in the agent port 8888, and check "Enable transparent HTTP proxying" to complete the setup on Charles. As shown in the following:

Settings on the iphone

First we need to get the IP address of the computer where Charles is running, open terminal, enter ifconfig en0 , and get the IP of that computer, as shown in:

In the iphone's "Settings", "Wireless LAN", you can see the current connected WiFi name, by clicking on the right of the details key, you can see the current connection of WiFi details, including IP address, subnet mask and other information. At the bottom of it is an "HTTP proxy", which we'll switch to manual, then fill in the IP of the computer where Charles is running and the port number 8888, as shown in:

After setting up, we open any program that needs network communication on the iphone, we can see Charles Pop-up iphone request connection Confirmation menu (as shown), click "Allow" to complete the setup.

Intercepting SSL Information

Charles does not intercept SSL by default, and if you want to intercept all SSL network requests on a Web site, you can right-click on the request and select SSL Proxy, as shown in:

In this way, all SSL requests for the host can be intercepted.

Analog Slow network

When it comes to iphone development, we often need to simulate a slow network or a high-latency network to test whether the application behaves properly under the mobile network. Charles has provided a good support for this requirement.

On the Charles menu, select "Proxy" –> "throttle Setting", and in the dialog that pops up, we can tick "Enable throttling", and you can set the type of throttle preset. As shown in the following:

If we only want to simulate the slow network of the specified site, you can tick the "only for selected hosts" item and then add the specified hosts to the lower half of the dialog box.

Modify Network Request Content

Sometimes in order to debug the server interface, we need to repeatedly try different parameters of the network request. Charles makes it easy to provide modification and re-sending of network requests. Simply right-click on a previous network request and select "Edit" to create an editable network request. As shown below:

We can modify any information about the request, including the URL address, port, parameters, etc., and then click "Execute" to send the modified network request (as shown). Charles supports us in modifying and sending this request several times, which is very convenient for us and the server-side debugging interface.

Summarize

With Charles Software, we can easily intercept and debug network request content, analyze packet protocols, and emulate slow networks in daily development. With good Charles, we can greatly facilitate the development and commissioning of apps with Web requests.

Reference Links:

    1. Charles main list of features

    2. Charles Official website

Posted by Tang Qiao Dec 11th, 2013IOS

Original article, copyright notice: Free Reprint-Non-commercial-non-derivative-retain attribution | Creative Commons by-nc-nd 3.0


iOS Development Tools-Network packet analysis tools Charles

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.