asp.net web api - Using a proxy with .NET 4.5 HttpClient -


i'm troubleshooting bug service call through .net's httpclient, trying route request through local proxy (fiddler), proxy settings seem not taking effect.

here's how create client:

private httpclient createhttpclient(commandcontext ctx, string sid) {     var cookies = new cookiecontainer();      var handler = new httpclienthandler {         cookiecontainer = cookies,         usecookies = true,         usedefaultcredentials = false,         proxy = new webproxy("http://localhost:8888", false, new string[]{}),         useproxy = true,     };      // snip out irrelevant setting of authentication cookies      var client = new httpclient(handler) {         baseaddress = _prefserverbaseurl,     };      client.defaultrequestheaders.accept.add(         new mediatypewithqualityheadervalue("application/json"));      return client; } 

then send request by:

var response = createhttpclient(ctx, sid).postasjsonasync("api/prefs/", smp).result; 

request goes straight server without attempting hit proxy. did miss?

this code worked me:

var httpclienthandler = new httpclienthandler                         {                             proxy = new webproxy("http://localhost:8888", false),                             useproxy = true                         } 

note not supplying empty array webproxy constructor. perhaps that's problem?


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -