Code is in F# but also tagging C# in case for any suggestions. It's an SSL based request for which it couldn't resolve the proxy name, I've tried both http://localhost and https://localhost besides 127.0.0.1
Code:
let request = WebRequest.Create("https://foo.example.com") :?> HttpWebRequest
let myproxy = WebProxy("http://127.0.0.1", 60103);
myproxy.BypassProxyOnLocal <- false;
request.Proxy <- myproxy;
Error:
System.Net.WebException: An error occurred while sending the request. Couldn't resolve proxy name ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.CurlException: Couldn't resolve proxy name
My configurations
Reverse Proxy Settings
Local port: 60103
Remote Hot: foo.example.com
Remote Port: 443
(Check box is enabled for both "Enable Reverse Proxies" and the above record itself)
SSL Proxy Settings
Host: foo.example.com
Port: 443
Both checkboxes are checked for "Enable SSL Proxying" and the record itself.
Under Help -> Proxying -> Install Charles Root Certificate, the certificate was installed and marked as trusted in keychain
It has been painful and I realize the mistake and here's the answer with the solution.
The cause of problem was a solution that worked for me in nodejs and it caused a confusion in here while not realizing that C#/F# provides a WebProxy class for that. nodejs doesn't have a WebProxy class (as per my knowledge) it so the concept is to use reverse proxy in nodejs, that is to send the request to localhost and a specific port which maps to the remote url.
So keep your URL same as where it should be pointed to and use WebProxy class here to point to localhost and port (8888 in my case) where Charles Proxy is listening and intercepting requests.
Thanks Fyodor Soikin for point out not to use the url (http:// etc.) and just use hostname.
// let url = "http://localhost:60103"; // don't do this, reverse proxy settings
let url = "https://example.com"; // keep the url intact
let request = WebRequest.Create(url) :?> HttpWebRequest
let myproxy = WebProxy("localhost", 8888); // port where Charles proxy is running
myproxy.BypassProxyOnLocal <- false;
request.Proxy <- myproxy;