Monday, March 7, 2016

C# use proxy with HttpClient request


Posting a JSON string to server using a proxy


var httpClientHandler = new HttpClientHandler
{
    Proxy = new WebProxy("http://localhost:8888", false),
    UseProxy = true
};
using (var client = new HttpClient(httpClientHandler))
{
    string apiUrl = "http://yourserver.com/postpage";
    StringContent content = new System.Net.Http.StringContent("{dataelem:value}", Encoding.UTF8, "application/json");
    HttpResponseMessage response = client.PostAsync(apiUrl, content).Result;
}


2 comments:

Unknown said...

Hello! thanks for share it! it helped to me.

Delnar said...

Thank you. This helped me as well.

Turn on Windows 11 Fast Boot

If windows starting is slow, to enable windows 11 fast startup/boot,  Press Windows + R, type powercfg.cpl, and hit Enter.  This will direct...