Problem description
in useCharles
When the tool captures packets, some application networks on the mobile phone will be unavailable, andCharles
After closing, the mobile phone has no network to use. You need to close the mobile agent before you can access the network normally.
However, the agent needs to be manually configured for the next packet capture, which is quite troublesome. Here, the automatic agent mode of the mobile phone can solve the problem of switching back and forth of agent configuration.
resolvent
First, create a new oneproxy.pac
The contents of the document are as follows:,url
Is the request path,host
Is the domain name. You can configure whether to perform proxy according to these two parameters.
Code description means when the domain name isxxx
Send the request to the proxy server with the address ofCharles
If the domain name is notxxx
Then proxy forwarding is not used,return "DIRECT";
Indicates no proxy forwarding.
function FindProxyForURL(url, host){
if(host == "xxxx" ) {
return "PROXY 192.168.2.82:8888";
}
return "DIRECT";
}
Put the configuration file on the server, which is used heremac
Built in server, turn it onApache
The server:sudo apachectl -k start
Enter in browserhttp://localhost/
, if displayedIt works
It indicates that the server is started successfully and the configuration file is thrown into the serverApache
Root directory:/Library/WebServer/Documents
。

Open the mobile phone, select the corresponding network in the network, enter the agent setting, select automatic agent, and enterproxy.pac
Address of the document, i.emac
ofIP
Address+proxy.pac
, as shown in the figure below, then store the agent configuration, exit the agent configuration, close the network, and then open the network. The agent configuration will take effect.
Remember to close the network after modifying the configuration file. The new configuration will not take effect until the network is turned on.