iosios 抓包 charless 怎么设置

Charles(最强大的http调试工具)详细教程(上) - 为程序员服务
Charles(最强大的http调试工具)详细教程(上)
Charles是目前最强大的http调试工具,在界面和功能上远强于,同时是全平台支持,堪称圣杯级工具,唯一的缺陷是这货是收费的,而且是要¥50美元大洋…当然网上是有破解版的,鄙视下自己,无耻地使用了…放在网盘里,亲可以默默带走,不要留下一片云彩。
先安装里面的原版,然后copy charles.jar覆盖到安装目录下的lib目录即可。这是V3.6版,最新版本是V3.8.3,但破解补丁不通用,会导致无法启动。
启动后,圣杯的真面目如上图。
Charles有个会话(session,不是指http中的session)的概念,可以理解为浏览器中的tab,这个功能在需要调试多个站点页面时很实用,当你刷新页面的时候,只会在当前session中捕获请求。
(PS:ctrl+N创建个新的session,ctrl+W关闭当前session)
Charles的代理服务器启动就可以使用(会提示给firefox安装插件),如果没有捕获到请求,请清理下浏览器缓存。
界面功能初探
工具条包含了Charles的大部分功能:
有几个功能比较抽象,后面会详细说明。
右键请求出现菜单,Charles的右键菜单功能比fiddler强大太多了。
双击请求进入列表视图,类似fiddler,方便查看和过滤请求。
Charles的过滤查找功能非常赞,很快速:
请求详情跟fiddler相似,但直观不少:
工具视图基本讲解完毕,接下来我们用Charles做点事情。
本地代理和远程代理
Charles的代理服务器端口跟fiddler一样都是8888,即你的本机ip:8888。
我们的目标将一个压缩文件代理成本地的源码文件。
点击“Map Local”后:
index-min.js代理成index.js,刷新页面试试。
代理成功,so easy!
Charles的树状视图比fiddler的列表视图好的地方在于,多次刷新后的请求会被归纳到树里面,更加一目了然,用fiddler的时候,有点强迫症的同学,都要点击clear,有木有…
Charles是支持子目录代理哦,非常实用的功能:(使用通配符*)
本地地址选择个子目录,不需要通配符。
如何判断是否代理成功呢?
这点Charles比fiddler人性化多了。
校验是否代理成功,最省力的方式是点击工具条上的刷新按钮,刷新单个请求,如果代理成功,Charles会往“Notes”界面打个log,比如Mapped to local file: C:\www\htdocs\gallery\uploader\1.5\build\index-min.js。
去除代理配置
小技巧:所有的配置开关都可以通过工具条上的“工具”设置(倒数第二个按钮)。
去掉代理配置:
小技巧:建议开启No Caching,不缓存请求。
mobile代理功能
手机或平板页面的调试,我们需要把请求代理到pc端的Charles上。
必须确保mobile端和pc端连的是相同的无线网络。
ios的配置非常简单
(上图借用我同事自寒的截图)
服务器ip设置成pc的ip,端口好设置成8888即可。
然后mobile终端可以刷新试试。
安卓机器的代理
首先,安卓机器必须有root权限,其次需要借助app才行,在安卓的任意市场搜索 ProxyDroid,灰常好用的代理app。
有些浏览器是自带了代理配置功能,比如opera mobile,输入opera:config ,不过我试了下没代理成功,不知道是不是手机问题。
wp8的代理设置也很简单,手机连接wifi 并进行设置下
设置–WiFi–长按连接好的WIFI–弹出编辑选项。
试试远程代理
Charles支持https和sockets的代理,还支持SSL,非常全面。
RIA三部曲:jquery、ext、flex
原文地址:, 感谢原作者分享。
您可能感兴趣的代码网络流量工具Charles的安装和用法
Charles是Mac下常用的对网络流量进行分析的工具,类似于Windows下的。在开发iOS程序的时候,往往需要调试客户端和服务器的API接口,这个时候就可以用Charles,Charles能够拦截SSL请求、模拟慢速网络、支持修改网络请求包并多次发送、能够篡改Request和Response等强大的功能。下面介绍安装和使用方法。
可以从这里Charles,有30天的试用期。
安装后打开Charles,试用版本会延迟10秒后加载。如下图:
第一次运行时会弹出如下提示,点击Grant Privileges即可。
然后打开菜单Proxy的Proxy Setting,设置端口为:8888。
如下图所示:
支持拦截SSL请求
根据官方的:
真实设备上的设置方法
如果要在真实设备上拦截SSL连接,需要安装证书,从下载即可。
下载证书之后,双击它,会有如下提示:
点击其中的“Always Trust”,然后输入自己的账号密码给它授权。
可以从Keychain中查看授权之后的结果:
模拟器上的设置方法
下载,解压之后双击,就可以在模拟器上拦截SSL请求了,甚至都不用重启模拟器。
设置iOS设备的代理
首先获取运行Charles的Mac的IP地址,可以打开命令行(Terminal)输入ifconfig得到IP地址。
或者spotlight 打开 Network Utility,如下图所示:
然后在iOS设备的WiFi网络中设置代理,如下图:
确保移动设备和Mac在同一个WIFI下面。
通过Charles分析iOS设备的网络请求
按下Record按钮,或者Proxy菜单里面的Start Recording即可对iOS设备的网络请求进行监听。
Charles的功能
拦截SSL请求
模拟慢速网络
菜单Proxy中的Throttle Setting可以对此进行设置
支持修改网络请求包并多次发送
Charles能够断到发送请求前(篡改Request)和请求后(篡改Response)
捕获记录控制
可以过滤出关注的请求。菜单Proxy中的Record Setting可以对此进行设置
暂时不展开介绍这些功能,这里介绍再多都比不上自己运行几分钟的效果好。
Charles还有很多强大的功能等待大家挖掘,欢迎大家使用下体验下这些功能。
喜欢做有趣的事情。微信公众账号:iOS技术分享
Powered by:
创建并维护Tutorial: Using Charles Proxy With Your iOS Development And HTTP Debugging
Total Shares 28
Every day, I’m building and working with applications that connect to remote data sources whether they’re files, feeds, databases, etc. I also do a lot of work daily involving video streaming to iOS devices. If you’ve had to build any sort of connected iOS app, I am pretty sure you’ve cursed at the iOS gods at one point or another when debugging some intermittent, hard-to-reproduce network bug. In times like those, being able to see what is being sent and received across the wire is invaluable and time-saving.
That’s where Charles Proxy comes in. With Charles, you’re able to peek into the network requests and responses that your app is making/receiving. I’m sure there are other types of tools out there that allow you to do the same thing but I really enjoy how easy Charles is to use.
Disclaimer: I’m in no way related or affiliated with the developer, Karl von Randow, nor am I getting paid or compensated to write this article. The sole purpose of writing this article is to show you guys how I use the tool to ease my iOS development and hope that it can help someone else as well.
Alright, let’s start with some scenarios you might encounter:
ARTICLE CONTENTS
Debugging HTTP Connection and Sessions
Your most basic use of Charles will be just having it running in the background while you test your application in the iOS simulator in XCode. In this way, you can actually capture the network calls that your app is making and what responses it is getting back.
Here are some scenarios where using Charles can be handy:
1. If you see an empty screen in your app when it’s supposed to fetch some data and display it, then the first thing I would check is if the data is actually being returned from the network request.
2. If you app is sending some data to a server to be saved or processed and you’re not getting the expected result.
3. Your app is making a call to some API and you’re not receiving the expected results.
4. And anything else that relates to your app making/receiving network calls/responses!
For any of the scenarios above and more, the first thing I would do is double-check that my app is sending the request and parameters that I’m expecting it to, and secondly, that my app is receiving the responses that it is expecting.
Monitoring that network traffic coming in and out of your app is as simple as having Charles Proxy open while you’re testing your application in the iOS Simulator. When you open Charles Proxy, don’t be alarmed if it starts logging things that your app isn’t connecting to. The proxy is monitoring all the network traffic from any app that you’re running.
Below is a screenshot of what Charles Proxy looks like.
On the left hand side, you can see the top level domains that your app is making requests to. You can expand the tree nodes to see the actual requests. Select a request to see the detail on the pane on the right hand side.
On the right hand side, you can see an overview of that specific network call such as latency, time elapsed etc. You’ll notice tabs near the top of the right hand side. Click “Request” or “Response” to view the actual data of the network request or response.
By inspecting the requests that your app is making and the data that is coming back, you’ll be able to identify issues that may end up causing you hours of headaches down the road.
Debugging Network Issues That Only Occur On Devices
Have you ever encountered a bug that you weren’t able to reproduce in the iOS Simulator but only later discovered that it is only reproducible on the actual device?
For me, that situation occurs more often than I’d like but it’s not all that surprising because as good as the Simulator is, at the end of the day, it is meant to simulate a real device. The best test is on the actual device(s) and platform(s) that your users will be using your app on.
For network related issues that are only reproducible on the actual iOS device, Charles Proxy can help you identify the cause of the bug (On a side note, there’ve been many cases where what I thought was NOT a network bug turned out to be indirectly caused by a network issue). You can test your app on your actual iOS device and see the network calls that it’s making and the responses that your app is receiving right from Charles on your laptop.
Here are the quick and easy steps to set this up:
Step 1 of 6: Make sure that your iOS device and your laptop are connected to the same wireless network.
Step 2 of 6: On your laptop (OSX) go into System Preferences -> Network to find your IP Address.
Step 3 of 6: Then on your iOS device, go into Settings, Wi-Fi
Step 4 of 6: Click the little arrow beside your wireless network to see the details of the network
Step 5 of 6: For the proxy settings at the bottom of the screen, select “Manual” and enter the IP Address you found on step 2 and the default port that Charles Proxy listens to is 8888.
Step 6 of 6: Now your iOS device will be connecting to the internet through your laptop on the port that Charles is monitoring. All your network requests from your iOS device will be viewable in your Charles window
Now you can test your application and see what network calls your app is making, and what responses it is getting back to help you troubleshoot all of those hard-to-resolve network related bugs.
Testing Your App In Various Network Conditions
Charles can be really helpful in testing your app in various network conditions. When you’re building your app in XCode with a strong internet connection, you’re missing out on all of those cases in the wild that your users will be experiencing such as Wi-Fi cutting in and out, slow 3G connections or internet connections dropping completely.
Your app will be really slick and polished if it handles all of these scenarios gracefully and doesn’t leave the user staring at a frozen UI or worst yet, having the app crash all together.
Within Charles, you have tools to either throttle the connection or stop it completely. The beauty of it, is that you can control this on a per host level so you can throttle only certain connections your app is making requests to and debug situations where the app never gets a response or gets a connection timeout.
Set up your proxy as described in the . In Charles, open up the menu “Proxy” -> Throttling Settings and you’ll see the menu below. As you can see, you can turn on throttling on a global level, for all hosts. Or you can enable it only for select hosts. The way I’ve got it set up below, throttling will be on for only the
domain and it will throttle it to a point where it simulates bandwidth over 3G.
Here’s a screenshot of the bandwidth presets you can set for your selected host or you can specify custom to set your own. A good way to test connection timeouts is if you throttle it to something really low like 0.01 kbps.
If you want to prevent your app from connecting to a host at all, such as simulating a situation where the server is completely unreachable, then you can blacklist a host. Just right click the host in the left pane and select “Blacklist” as shown in the screenshot below. To see the list of currently blacklisted hosts and to modify the list, go to the menu item “Tools” -> “Black list…”
Debugging Video Streaming Issues
Charles is a good way to debug video streaming issues, especially authenticated streams. If your Charles Proxy is hooked up and you monitor your video playback on your application you can see the video chunks being downloaded.
Combined with the throttling tips in the , you can test your video playback under a variety of low bandwidth and high bandwidth situations.
Other situations that may occur during video playback are concurrency restriction limits being hit or being unable to authenticate after idling on the playback screen for a long time. These are some of the common situations that may occur for video playback applications and Charles Proxy can help save you a lot of time in debugging them!
Debugging Airplay Related Issues
Charles Proxy is helpful for debugging Airplay related issues because you can’t test Airplay on the iOS simulator. If you test Airplay on your device and you encounter problems, it could be very difficult to see what’s going on.
I’ve encountered issues before with video streaming where toggling back and forth between playing the video through Airplay and playing the video on the device will, at some point, cause the video not to stream anymore, leaving the user staring at a black screen.
With Charles Proxy, I was able to set up the proxy like
and then run my test case of toggling back and forth between playing the video stream on my iOS device and on my TV through Airplay.
What I discovered was that in the process of passing the stream back and forth between my TV and the iOS device, the content delivery network serving the video would deny the request for the m3u8 playlist. At that point, the user was left staring at a black screen. Without Charles Proxy, I would probably be left tearing my hair out, trying to figure out what was wrong!
Discovering Vulnerabilities In Your App
A really nifty feature of Charles Proxy is called Breakpoints. This allows you to specify any host (you can get as granular as indicating a certain URL with specific parameters) as a breakpoint and when your app makes a request or receives a response from something that matches your breakpoint, it will pause request/response to give you an opportunity to analyze and edit the request/response before it continues to it’s destination.
This is something that a malicious user could attempt to do to your application and try to trick your app into unlocking features, gaining unauthorized access, submitting high scores and inducing other undesired behaviour.
Using Charles Proxy with Breakpoints will give you the ability to put on the “hacker” hat and try to break your own app.
Set breakpoints on those resources/servers that your app relies on to get configuration information, receive data and submit data. Then use your application as a normal user would and when Charles Proxy breaks on the breakpoints, modify the request/response values to try to break your app and find security vulnerabilities.
Here’s how to do it:
Below, the red hexagonal button is the toggle to turn breakpoints on or off. If you don’t have any specific hosts set up in your breakpoints list then toggling breakpoints on will do nothing. Read further below to see how to put specific hosts into your breakpoints list.
To add something to your breakpoints list, you can right click on a specific request in the left pane of Charles and simply choose “Breakpoints”. When you do this, it will automatically toggle Breakpoints to be ON.
You can see in the lower right hand corner of your Charles window whether Breakpoints are on or off.
In the menu “Proxy”, if you click the menu item, “Breakpoints”, you’ll see the window below which lists the current locations that you’ll break on. You can even add or remove locations from this menu as well.
Apps that do client side processing and then sends the results to a server are especially susceptible because the server expects to receive accurate information from the client side app. If someone is able to intercept the request before it gets to the server and change it’s values first, then you’ve got yourself a security concern!
As to how to resolve those vulnerabilities, that’s a different discussion altogether but the point here is that Charles Proxy can help you identify those security holes.
I hope that this article exemplifies the usefulness of a tool like Charles Proxy in helping you develop and debug your applications. I’ve only touched a subset of all the available features of this tool! I’ll update this article as I learn and squeeze out more functionality from it.
Please take a moment to leave a comment and share this with your friends who may find it helpful!
Total Shares 28Charles 从入门到精通
目录与版权转载请保留顶部的 Charles 中国特惠内容,本文的内容主要包括:Charles 的简介如何安装 Charles将 Charles 设置成系统代理Charles 主界面介绍过滤网络请求截取 iPhone 上的网络封包截取 Https 通讯信息模拟慢速网络修改网络请求内容给服务器做压力测试修改服务器返回内容总结简介Charles&是在 Mac 下常用的网络封包截取工具,在做 移动开发时,我们为了调试与服务器端的网络通讯协议,常常需要截取网络封包来分析。Charles 通过将自己设置成系统的网络访问代理服务器,使得所有的网络访问请求都通过它来完成,从而实现了网络封包的截取和分析。除了在做移动开发中调试端口外,Charles 也可以用于分析第三方应用的通讯协议。配合 Charles 的 SSL 功能,Charles 还可以分析 Https 协议。Charles 是收费软件,可以免费试用 30 天。试用期过后,未付费的用户仍然可以继续使用,但是每次使用时间不能超过 30 分钟,并且启动时将会有 10 秒种的延时。因此,该付费方案对广大用户还是相当友好的,即使你长期不付费,也能使用完整的软件功能。只是当你需要长时间进行封包调试时,会因为 Charles 强制关闭而遇到影响。Charles 主要的功能包括:截取 Http 和 Https 网络封包。支持重发网络请求,方便后端调试。支持修改网络请求参数。支持网络请求的截获并动态修改。支持模拟慢速网络。安装 Charles去 Charles 的官方网站()下载最新版的 Charles 安装包,是一个 dmg 后缀的文件。打开后将 Charles 拖到 Application 目录下即完成安装。将 Charles 设置成系统代理之前提到,Charles 是通过将自己设置成代理服务器来完成封包截取的,所以使用 Charles 的第一步是将其设置成系统的代理服务器。启动 Charles 后,第一次 Charles 会请求你给它设置系统代理的权限。你可以输入登录密码授予 Charles 该权限。你也可以忽略该请求,然后在需要将 Charles 设置成系统代理时,选择菜单中的 “Proxy” –& “Mac OS X Proxy” 来将 Charles 设置成系统代理。如下所示:之后,你就可以看到源源不断的网络请求出现在 Charles 的界面中。需要注意的是,Chrome 和 Firefox 浏览器默认并不使用系统的代理服务器设置,而 Charles 是通过将自己设置成代理服务器来完成封包截取的,所以在默认情况下无法截取 Chrome 和 Firefox 浏览器的网络通讯内容。如果你需要截取的话,在 Chrome 中设置成使用系统的代理服务器设置即可,或者直接将代理服务器设置成&127.0.0.1:8888&也可达到相同效果。Charles 主界面介绍Charles 主要提供两种查看封包的视图,分别名为 “Structure” 和 “Sequence”。Structure 视图将网络请求按访问的域名分类。Sequence 视图将网络请求按访问的时间排序。大家可以根据具体的需要在这两种视图之前来回切换。请求多了有些时候会看不过来,Charles 提供了一个简单的 Filter 功能,可以输入关键字来快速筛选出 URL 中带指定关键字的网络请求。对于某一个具体的网络请求,你可以查看其详细的请求内容和响应内容。如果请求内容是 POST 的表单,Charles 会自动帮你将表单进行分项显示。如果响应内容是 JSON 格式的,那么 Charles 可以自动帮你将 JSON 内容格式化,方便你查看。如果响应内容是图片,那么 Charles 可以显示出图片的预览。过滤网络请求通常情况下,我们需要对网络请求进行过滤,只监控向指定目录服务器上发送的请求。对于这种需求,以下几种办法:方法一:在主界面的中部的 Filter 栏中填入需要过滤出来的关键字。例如我们的服务器的地址是:&, 那么只需要在 Filter 栏中填入 yuantiku 即可。方法二:在 Charles 的菜单栏选择 “Proxy”–&“Recording Settings”,然后选择 Include 栏,选择添加一个项目,然后填入需要监控的协议,主机地址,端口号。这样就可以只截取目标网站的封包了。如下图所示:通常情况下,我们使用方法一做一些临时性的封包过滤,使用方法二做一些经常性的封包过滤。方法三:在想过滤的网络请求上右击,选择 “Focus”,之后在 Filter 一栏勾选上 Focussed 一项,如下图所示:这种方式可以临时性的,快速地过滤出一些没有通过关键字的一类网络请求。截取 iPhone 上的网络封包Charles 通常用来截取本地上的网络封包,但是当我们需要时,我们也可以用来截取其它设备上的网络请求。下面我就以 iPhone 为例,讲解如何进行相应操作。Charles 上的设置要截取 iPhone 上的网络请求,我们首先需要将 Charles 的代理功能打开。在 Charles 的菜单栏上选择 “Proxy”–&“Proxy Settings”,填入代理端口 8888,并且勾上 “Enable transparent HTTP proxying” 就完成了在 Charles 上的设置。如下图所示:iPhone 上的设置首先我们需要获取 Charles 运行所在电脑的 IP 地址,Charles 的顶部菜单的 “Help”–&“Local IP Address”,即可在弹出的对话框中看到 IP 地址,如下图所示:在 iPhone 的 “ 设置 ”–&“ 无线局域网 ” 中,可以看到当前连接的 wifi 名,通过点击右边的详情键,可以看到当前连接上的 wifi 的详细信息,包括 IP 地址,子网掩码等信息。在其最底部有「HTTP 代理」一项,我们将其切换成手动,然后填上 Charles 运行所在的电脑的 IP,以及端口号 8888,如下图所示:设置好之后,我们打开 iPhone 上的任意需要网络通讯的程序,就可以看到 Charles 弹出 iPhone 请求连接的确认菜单(如下图所示),点击 “Allow” 即可完成设置。截取 Https 通讯信息安装证书如果你需要截取分析 Https 协议相关的内容。那么需要安装 Charles 的 CA 证书。具体步骤如下。首先我们需要在 Mac 电脑上安装证书。点击 Charles 的顶部菜单,选择 “Help” –& “SSL Proxying” –& “Install Charles Root Certificate”,然后输入系统的帐号密码,即可在 KeyChain 看到添加好的证书。如下图所示:需要注意的是,即使是安装完证书之后,Charles 默认也并不截取 Https 网络通讯的信息,如果你想对截取某个网站上的所有 Https 网络请求,可以在该请求上右击,选择 SSL proxy,如下图所示:这样,对于该 Host 的所有 SSL 请求可以被截取到了。截取移动设备中的 Https 通讯信息如果我们需要在 iOS 或 Android 机器上截取 Https 协议的通讯内容,还需要在手机上安装相应的证书。点击 Charles 的顶部菜单,选择 “Help” –& “SSL Proxying” –& “Install Charles Root Certificate on a Mobile Device or Remote Browser”,然后就可以看到 Charles 弹出的简单的安装教程。如下图所示:按照我们之前说的教程,在设备上设置好 Charles 为代理后,在手机浏览器中访问地址:/getssl,即可打开证书安装的界面,安装完证书后,就可以截取手机上的 Https 通讯内容了。不过同样需要注意,默认情况下 Charles 并不做截取,你还需要在要截取的网络请求上右击,选择 SSL proxy 菜单项。模拟慢速网络在做移动开发的时候,我们常常需要模拟慢速网络或者高延迟的网络,以测试在移动网络下,应用的表现是否正常。Charles 对此需求提供了很好的支持。在 Charles 的菜单上,选择 “Proxy”–&“Throttle Setting” 项,在之后弹出的对话框中,我们可以勾选上 “Enable Throttling”,并且可以设置 Throttle Preset 的类型。如下图所示:如果我们只想模拟指定网站的慢速网络,可以再勾选上图中的 “Only for selected hosts” 项,然后在对话框的下半部分设置中增加指定的 hosts 项即可。修改网络请求内容有些时候为了调试服务器的接口,我们需要反复尝试不同参数的网络请求。Charles 可以方便地提供网络请求的修改和重发功能。只需要在以往的网络请求上点击右键,选择 “Edit”,即可创建一个可编辑的网络请求。如下所示:我们可以修改该请求的任何信息,包括 URL 地址、端口、参数等,之后点击 “Execute” 即可发送该修改后的网络请求(如下图所示)。Charles 支持我们多次修改和发送该请求,这对于我们和服务器端调试接口非常方便,如下图所示:给服务器做压力测试我们可以使用 Charles 的 Repeat 功能来简单地测试服务器的并发处理能力,方法如下。我们在想打压的网络请求上(POST 或 GET 请求均可)右击,然后选择 「Repeat Advanced」菜单项,如下所示:接着我们就可以在弹出的对话框中,选择打压的并发线程数以及打压次数,确定之后,即可开始打压。悄悄说一句,一些写得很弱的投票网站,也可以用这个办法来快速投票。当然,我也拿 Charles 的 Repeat 功能给一些诈骗的钓鱼网站喂了不少垃圾数据,上次不小心还把一个钓鱼网站的数据库打挂了,嗯,请叫我雷锋。修改服务器返回内容有些时候我们想让服务器返回一些指定的内容,方便我们调试一些特殊情况。例如列表页面为空的情况,数据异常的情况,部分耗时的网络请求超时的情况等。如果没有 Charles,要服务器配合构造相应的数据显得会比较麻烦。这个时候,使用 Charles 相关的功能就可以满足我们的需求。根据具体的需求,Charles 提供了 Map 功能、 Rewrite 功能以及 Breakpoints 功能,都可以达到修改服务器返回内容的目的。这三者在功能上的差异是:Map 功能适合长期地将某一些请求重定向到另一个网络地址或本地文件。Rewrite 功能适合对网络请求进行一些正则替换。Breakpoints 功能适合做一些临时性的修改。Map 功能Charles 的 Map 功能分 Map Remote 和 Map Local 两种,顾名思义,Map Remote 是将指定的网络请求重定向到另一个网址请求地址,Map Local 是将指定的网络请求重定向到本地文件。在 Charles 的菜单中,选择 “Tools”–&“Map Remote” 或 “Map Local” 即可进入到相应功能的设置页面。对于 Map Remote 功能,我们需要分别填写网络重定向的源地址和目的地址,对于不需要限制的条件,可以留空。下图是一个示例,我将所有&ytk1.yuanku.ws(测试服务器)的请求重定向到了&(线上服务器)。对于 Map Local 功能,我们需要填写的重定向的源地址和本地的目标文件。对于有一些复杂的网络请求结果,我们可以先使用 Charles 提供的 “Save Response…” 功能,将请求结果保存到本地(如下图所示),然后稍加修改,成为我们的目标映射文件。下图是一个示例,我将一个指定的网络请求通过 Map Local 功能映射到了本地的一个经过修改的文件中。Rewrite 功能Rewrite 功能功能适合对某一类网络请求进行一些正则替换,以达到修改结果的目的。例如,我们的客户端有一个 API 请求是获得用户昵称,而我当前的昵称是 “tangqiaoboy”,如下所示:我们想试着直接修改网络返回值,将 tangqiaoboy 换成成 iosboy。于是我们启用 Rewrite 功能,然后设置如下的规则:完成设置之后,我们就可以从 Charles 中看到,之后的 API 获得的昵称被自动 Rewrite 成了 iosboy,如下图所示:Breakpoints 功能上面提供的 Rewrite 功能最适合做批量和长期的替换,但是很多时候,我们只是想临时修改一次网络请求结果,这个时候,使用 Rewrite 功能虽然也可以达到目的,但是过于麻烦,对于临时性的修改,我们最好使用 Breakpoints 功能。Breakpoints 功能类似我们在 Xcode 中设置的断点一样,当指定的网络请求发生时,Charles 会截获该请求,这个时候,我们可以在 Charles 中临时修改网络请求的返回内容。下图是我们临时修改获取用户信息的 API,将用户的昵称进行了更改,修改完成后点击 “Execute” 则可以让网络请求继续进行。需要注意的是,使用 Breakpoints 功能将网络请求截获并修改过程中,整个网络请求的计时并不会暂停,所以长时间的暂停可能导致客户端的请求超时。总结通过 Charles 软件,我们可以很方便地在日常开发中,截取和调试网络请求内容,分析封包协议以及模拟慢速网络。用好 Charles 可以极大的方便我们对于带有网络请求的 App 的开发和调试。愿本文帮助大家成为 Charles 的专家,祝大家玩得开心~转自:&/blog//charles-introduction/
无相关信息
最新教程周点击榜
微信扫一扫

我要回帖

更多关于 ios 抓包 charles 的文章

 

随机推荐