2

I am using the HttpClient class to make GET requests, it works perfectly without proxy, but when I try to make a request thought a proxy server, it adds hostname in the path and there is also hostname in headers, so the full url is like http://google.comhttp://google.com/

The code:

static void GetSmth()
{
    var baseAddr = new Uri("http://google.com");

    var handler = new HttpClientHandler
    {
        AllowAutoRedirect = false,
        UseCookies = true,
        UseProxy = true,
        Proxy = new WebProxy("111.56.13.168:80", true),

    };
    HttpClient client = new HttpClient(handler);
    client.BaseAddress = baseAddr;
     HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "/");
    var resp = client.SendAsync(request).Result;   
}

Wireshark screenshot:

Wireshark

What is wrong with it?

Nate Barbettini
  • 51,256
  • 26
  • 134
  • 147
MIkhail
  • 31
  • 2
  • It seems this new library is kind of buggy indeed http://stackoverflow.com/questions/23438416/why-is-httpclient-baseaddress-not-working. Maybe you can try add a slash after your URL into `http://google.com/` ? If still doesn't work, try remove the slash within HttpRequestMessage into an empty string. – Thariq Nugrohotomo Apr 09 '16 at 00:44

0 Answers0