Add header to requests with Charles

2019-07-29 08:49发布

问题:

I am trying to use Charles (http://www.charlesproxy.com) to add a header to every HTTP request I execute in a browser. The web app I am using is relying on a header to work correctly. I have setup a rewrite rule to add a header like this:

Charles error log shows that the request is matched and it says it added the header:

2017/05/24 16:34:04 INFO     com.xk72.charles.tools.rewrite.RewriteFilter          CONNECT https://www.googleapis.com   Testing: Add Header: MY_HEADER:MY_HEADER_VALUE
2017/05/24 16:34:04 INFO     com.xk72.charles.tools.rewrite.RewriteFilter          CONNECT https://www.googleapis.com   Matched: Add Header: MY_HEADER:MY_HEADER_VALUE  Rewrite: MY_HEADER_VALUE

But when I try to open the web app in question in Chrome by typing in a url and when I inspect the traffic in Chrome Dev Tools, I don't see the header and my app doesn't work.

回答1:

Your browser will show the request as it as sent from the browser. If the request is modified after being sent, e.g: by a proxy or a gateway, these changes will not be reflected in that view (but will be still applied to the request).

Charles should show the edit request.

In addition you can use a traffic monitor (aka sniffer) to see exactly what is being transmitted, such as Wireshark, however Charles should suffice in this case.