12

I'm trying to use Charles to map requests for my server to localhost on my Mac. The server is on HTTPS and the local is HTTP. I'm trying that from the Chrome browser, iOS simulator and Postman. it always fails.

I set map remote in charles from my-server.com/* to http://localhost:PORT. If I try https://my-server.com/, charles maps the request but I get error in CONNECT request. If I try http://my-server.com, the request succeeds.

EDIT: There is an answer that suggests rewrite instead of map remote. it is good and working, but it feels to me as a workaround. I would like to use map remote as usual. I guess it require both Charles setup and machine setup

gutte
  • 1,373
  • 2
  • 19
  • 31
  • Have you installed the CharlesProxy certificate in your HTTP clients (browser, postman, etc.: https://www.charlesproxy.com/documentation/proxying/ssl-proxying/)? If so, could you paste the result of both HTTP requests using "curl --insecure"? – Lluís Suñol May 09 '18 at 10:40
  • I did install the certificates. I use Charles for years... What do you mean by 'both HTTP requests'? – gutte May 09 '18 at 12:58
  • I meant: 1) `curl --insecure "https://my-server.com"` 2) `curl "http://my-server.com"`. The response will need some text formatting, so I reccomend you to add the info directly to the question rather than in another comment. – Lluís Suñol May 15 '18 at 14:44

4 Answers4

18

You should try using the Rewrite function like this:

enter image description here

kubano
  • 633
  • 7
  • 10
  • 1
    An important note: you must **disable SSL proxying** in Charles settings: go to menu Proxy->SSL Proxying Settings and clear "Enable SSL Proxying" checkbox, then click OK to save changes. Otherwise Charles will try connecting via HTTPS **before** applying URL rewrite! – izogfif Aug 05 '19 at 10:59
  • 1
    I found the opposite to be true in v4.5.6 (I needed to have SSL proxying enabled). I also found it was important to use a real host as match in the rewrite rule, otherwise I got a DNS error in Charles. It seems the DNS lookup must happen before the rewrite. – Michael Rush Oct 17 '20 at 00:57
4

enter image description here

As @kubano suggested, I'm using REWRITE tool with URL rewrite. In order to map all subpaths, I'm using regex group to replace the hostname but re-attach all that comes after '.com'. When wrapping something with () it is referred as 'group' and you can use it with $1 $2 ... and so on. in this case, what ever comes after '.com' is referred as $1 in the replace section

gutte
  • 1,373
  • 2
  • 19
  • 31
3

I suggest using Map Remote from Proxyman to map between HTTP <-> HTTPS which is easier to setup.

Just create a rule, set HTTPS to HTTP, and the host. It will map from https://your-server.com to http://localhost:3000

Doc: https://docs.proxyman.io/advanced-features/map-remote

enter image description here

Disclaimer: I'm the creator of Proxyman and hopefully it would help you.

Nghia Tran
  • 2,600
  • 2
  • 16
  • 25
0

In case somebody comes here to search for how to map local (file) from an https location (which did not work for me out of the box):

Similar to the rewrite rule (in Charles 4 at least) it works with map remote, mapping https to an http location (e.g localhost) and then mapping that (localhost) url to a file enter image description here

  • 1
    Mapping to local files works fine for me for both https and http. can you share the map local rule that failed for you? – gutte Apr 04 '19 at 10:19