The original article is reprinted from liu Yue’s Technology blog v3u.cn/a_id_118

For example, I want to check the parameters and return values of an interface request, as well as HTTP and HTTPS requests on mobile devices. This time, the background is that we want to capture some videos on the APP end and small program end. Tencent Video is used as an example. Charles software of MAC system (similar to Fiddler in Win system, with little difference) is used to capture and sniff the video interface and address.

At the same time, the packet capture tool is also conducive to the analysis of the problems in the online production environment. A few days ago, a student working on the server told me that he did not need the packet capture tool and could directly debug the code when encountering problems. Then I asked him, if the online service is used, how can you adjust the code? In the real project, don’t you encounter the client to fight with each other? The client says he’s fine, the server says he’s fine, so who’s got a problem? There is no need to shirk each other at this point, the data is king. What does the packet capture tool do? It is the client request data, as well as the data returned by the server to complete the capture down, for the siege lion analysis of the problem. So it’s important to analyze the problem first, rather than track down code debugs first

Charles is an HTTP proxy server,HTTP monitor, reverse proxy server, Charles can monitor all data sent and received by the browser when the browser connects to Charles’s proxy to access the Internet. It allows a developer to view all HTTP traffic connected to the Internet, including Request, Response, and HTTP headers (including cookies and caching information).

First installation, Charles, can be directly go to the website to download www.charlesproxy.com/latest-rele… The latest version is 4.5.1, and it’s worth mentioning that Charles also supports 64-bit Windows

Once installed, open Charles and open the agent in the menu

In this way, Charles creates a proxy service directly locally, with the default port number 8888

Run the command line interface (CLI) and enter ifconfig(ipconfig in Win) to view the LOCAL LAN IP address

Connect your phone and computer to the unified LAN, then set the advanced Settings for wifi connection, and enter the local IP address and port number into the proxy Settings

At this point, all network requests from the mobile phone can be displayed in the Charles interface on the PC

Open Tencent Video APP or Tencent Video small program in the mobile phone, randomly open a video

We see all the requests including the video address, which we copy to the browser to view

In this way, we get the video played on the mobile end, and then we can directly download it locally by command or writing python script. Here, we use the Linux command wget

wget http://ugcws.video.gtimg.com/uwMROfz2r5zEYaQXGdGnC2dfDmZ8QagOBRrURGecmSBtB5p6/u0851ed5e06.mp4?vkey=2F247F5C2A6500312D6F6 B52E65F53DC4770569E7A9710825CEA1DC8A0E99927E68B68C5C83D12E503C70DB9FDE136B95AD4FBA7C169FF1E334F8584173754F9E76E83D5A5A4E 4D5CA182AA0E0C478B59C2AEAFBEEFF14CB2531CF18881741B1CEA42BACB9150D485459FA19B14D194D85A3EE1F34E61433Copy the code

The video has been downloaded locally and can be played at any time

Points to note:

1. When we do not capture packets, we will close Charles. At this time, your mobile phone cannot access the network, because the proxy (namely Charles) is set.

2. Charles captures, the wifi connected to the computer and mobile phone must be kept in the same network environment.

The original article is reprinted from liu Yue’s Technology blog v3u.cn/a_id_118