IOS # Charles intercepts network data

Source: Internet
Author: User

Charles :

is commonly used in MAC interception of network packets, in the development of iOS, in order to debug and server-side network communication protocols, often need to intercept network packets to analyze. 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 ' 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 & Introduction:

1, the official website (http://www.charlesproxy.com) Download the latest version of the Charles installation package;

2, 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 popup menu.

3. Charles Packet View: "Structure" & "Sequence"

    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.

Original link: http://www.devtang.com/blog/categories/ios/

-------------

TODO:

--Collection & Sharing

1. Download Charles Grab Bag tool (IOS):-- has cracked, can be used directly!

: Http://yun.baidu.com/s/1GvxaY

2. intercept the network packet on the iphone: "- -Main

1.[clarles Settings] Opens the agent function for Charles. On Charles's menu bar, choose "Proxy", "proxy Settings"

Fill in the proxy port 8888, and tick "Enable transparent HTTP proxying" to complete the setup on Charles.

2.[iphone Settings] will get to the computer IP address (terminal $ifconfig en0-- View the IP address of the NIC En0 ), under the same LAN of the iphone, set the HTTP proxy protocol

Fill in the IP of the computerand write to Port 8888.

3. 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.

4, analog slow network to obtain data:

Why: 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.

  TODO: In Charles's menu, select "Proxy", "throttle Setting", tick "Enable throttling", and you can set the throttle The type of preset.

5. Modify the contents of the network request :

Sometimes in order to debug the server interface, we need to repeatedly try different parameters of the network request.

Charles provides: "Modification of Network Requests" and "re-send" functions. Simply right-click on a previous network request and select "Edit" to create an editable network request.

PS: We can modify any information about the request, including the URL address, port, parameters, etc., then click "Execute" to send the modified network request (as shown in).

Charles supports us in modifying and sending this request several times, which is very convenient for us and the server-side debugging interface.

6, Filter Network Request "----Main

Typically, we need to filter the network requests and only monitor requests sent to the specified directory server. We have 2 ways to do this.

    1. Fill in the filter bar in the middle of the main interface with keywords that need to be filtered out. For example, the address of our server is: http://www.baidu.com, then only need to fill in the filter bar Baidu.

    2. In Charles's menu bar, select "Proxy", "Recording Settings", then select the Include column, select Add an item, and then fill in the protocol, host address, port number you want to monitor. This allows you to intercept only the packets of the target site.

  TODO: ["Proxy", "recording Setting", "Include", "Add") What to fill in: http, baidu.com

--------------------

"NetEase News"--data interception:

[C.m.163.com/nc/article/headline/t1348647853363/0-100.html]

- (void) LoadData {nsurl*url = [Nsurl urlwithstring:@"http://c.m.163.com/nc/article/headline/T1348647853363/0-20.html"]; Nsurlrequest*request =[Nsurlrequest Requestwithurl:url]; [Nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] CompletionHandler:^ (Nsurlresponse *response, NSData *data, Nserror *connectionerror) {Nsdictionary*dict = [nsjsonserialization jsonobjectwithdata:data options:0Error:null];//NSLog (@ "%@", dict); //get the array of the first item in the dictionary//use Keyenumerator.nextobject to quickly traverse a dictionary's key valuesNSLog (@"%@", Dict.keyEnumerator.nextObject); //Dictionary key value of the tips, for NetEase news, you can directly filter out the first layer  of the DictionaryNsarray *array =Dict[dict.keyenumerator.nextobject]; NSLog (@"%@", array); //iterate through arrays, dictionary to modelNsmutablearray *arraym =[Nsmutablearray ArrayWithCapacity:array.count]; [Array Enumerateobjectsusingblock:^ (nsdictionary *dict, Nsuinteger idx, BOOL *stop) {News*news =[News newswithdict:dict];                        [Arraym Addobject:news]; NSLog (@"%@", News.objectinfo);    }]; }];}

|--> Copyright (c) Bing Ma.

|--> GitHub RUL: https://github.com/SpongeBob-GitHub

IOS # Charles intercepts network data

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.