Using a proxy with .NET 4.5 HttpClientc# Accessing API via system's proxy'UTF8' is not a supported encoding nameC# Web API - Internal Server Error 500Use Proxy in C# Portable Class Library (Microsoft.Net.Http)TCP connections are stacked until 65k when using HttpWebRequest fetching function - internet connectivity is lostSending email in .NET through GmailHow to escape braces (curly brackets) in a format string in .NET.NET String.Format() to add commas in thousands place for a numberDifference between decimal, float and double in .NET?How can I get the application's path in a .NET console application?Reading settings from app.config or web.config in .netNew HttpClient proxy settings issuesRetargeting solution from .Net 4.0 to 4.5 - how to retarget the NuGet packages?Pass windows identity to web api layerCookieContainer memory leak
Designing a magic-compatible polearm
Is there a term for the belief that "if it's legal, it's moral"?
Am I legally required to provide a (GPL licensed) source code even after a project is abandoned?
How does DC work with natural 20?
I just entered the USA without passport control at Atlanta airport
Greeting with "Ho"
How can a warlock learn from a spellbook?
Counterfeit checks were created for my account. How does this type of fraud work?
What are Elsa's reasons for selecting the Holy Grail on behalf of Donovan?
How do internally carried IR missiles acquire a lock?
What does it cost to buy a tavern?
Dates on degrees don’t make sense – will people care?
Subtract the Folded Matrix
QGIS. Polygon doesn't repeat itself
Why isn't my calculation that we should be able to see the sun well beyond the observable universe valid?
What happened to Hopper's girlfriend in season one?
FD Battery Stations... How Do You Log?
What are the current battlegrounds for people’s “rights” in the UK?
What is the meaning of "понаехать"?
Is the specular reflection on a polished gold sphere white or gold in colour?
Mathematically modelling RC circuit with a linear input
Why don't countries like Japan just print more money?
How much steel armor can you wear and still be able to swim?
Rejecting an offer after accepting it just 10 days from date of joining
Using a proxy with .NET 4.5 HttpClient
c# Accessing API via system's proxy'UTF8' is not a supported encoding nameC# Web API - Internal Server Error 500Use Proxy in C# Portable Class Library (Microsoft.Net.Http)TCP connections are stacked until 65k when using HttpWebRequest fetching function - internet connectivity is lostSending email in .NET through GmailHow to escape braces (curly brackets) in a format string in .NET.NET String.Format() to add commas in thousands place for a numberDifference between decimal, float and double in .NET?How can I get the application's path in a .NET console application?Reading settings from app.config or web.config in .netNew HttpClient proxy settings issuesRetargeting solution from .Net 4.0 to 4.5 - how to retarget the NuGet packages?Pass windows identity to web api layerCookieContainer memory leak
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm troubleshooting a bug with a service I call through .NET's HttpClient, trying to route the request through a local proxy (Fiddler), but my proxy settings seem to not be taking effect.
Here's how I create the 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 some irrelevant setting of authentication cookies
var client = new HttpClient(handler)
BaseAddress = _prefServerBaseUrl,
;
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
return client;
then I send the request by:
var response = CreateHttpClient(ctx, sid).PostAsJsonAsync("api/prefs/", smp).Result;
Request goes straight to the server without attempting to hit the proxy. What did I miss?
.net asp.net-web-api .net-4.5
add a comment |
I'm troubleshooting a bug with a service I call through .NET's HttpClient, trying to route the request through a local proxy (Fiddler), but my proxy settings seem to not be taking effect.
Here's how I create the 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 some irrelevant setting of authentication cookies
var client = new HttpClient(handler)
BaseAddress = _prefServerBaseUrl,
;
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
return client;
then I send the request by:
var response = CreateHttpClient(ctx, sid).PostAsJsonAsync("api/prefs/", smp).Result;
Request goes straight to the server without attempting to hit the proxy. What did I miss?
.net asp.net-web-api .net-4.5
Is your service under test on your local machine? Consider proxy bypassing for local addresses.
– Xaqron
May 13 '13 at 16:33
By the way, creatingHttpClient
instances is expensive. You should reuse instances whenever possible. There are a few blog posts that talk about this reachable using Google.
– NathanAldenSr
May 13 '16 at 2:07
add a comment |
I'm troubleshooting a bug with a service I call through .NET's HttpClient, trying to route the request through a local proxy (Fiddler), but my proxy settings seem to not be taking effect.
Here's how I create the 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 some irrelevant setting of authentication cookies
var client = new HttpClient(handler)
BaseAddress = _prefServerBaseUrl,
;
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
return client;
then I send the request by:
var response = CreateHttpClient(ctx, sid).PostAsJsonAsync("api/prefs/", smp).Result;
Request goes straight to the server without attempting to hit the proxy. What did I miss?
.net asp.net-web-api .net-4.5
I'm troubleshooting a bug with a service I call through .NET's HttpClient, trying to route the request through a local proxy (Fiddler), but my proxy settings seem to not be taking effect.
Here's how I create the 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 some irrelevant setting of authentication cookies
var client = new HttpClient(handler)
BaseAddress = _prefServerBaseUrl,
;
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
return client;
then I send the request by:
var response = CreateHttpClient(ctx, sid).PostAsJsonAsync("api/prefs/", smp).Result;
Request goes straight to the server without attempting to hit the proxy. What did I miss?
.net asp.net-web-api .net-4.5
.net asp.net-web-api .net-4.5
edited Feb 29 '16 at 14:57
Uwe Keim
27.9k32140220
27.9k32140220
asked May 13 '13 at 16:17
Mike RuhlinMike Ruhlin
2,85011630
2,85011630
Is your service under test on your local machine? Consider proxy bypassing for local addresses.
– Xaqron
May 13 '13 at 16:33
By the way, creatingHttpClient
instances is expensive. You should reuse instances whenever possible. There are a few blog posts that talk about this reachable using Google.
– NathanAldenSr
May 13 '16 at 2:07
add a comment |
Is your service under test on your local machine? Consider proxy bypassing for local addresses.
– Xaqron
May 13 '13 at 16:33
By the way, creatingHttpClient
instances is expensive. You should reuse instances whenever possible. There are a few blog posts that talk about this reachable using Google.
– NathanAldenSr
May 13 '16 at 2:07
Is your service under test on your local machine? Consider proxy bypassing for local addresses.
– Xaqron
May 13 '13 at 16:33
Is your service under test on your local machine? Consider proxy bypassing for local addresses.
– Xaqron
May 13 '13 at 16:33
By the way, creating
HttpClient
instances is expensive. You should reuse instances whenever possible. There are a few blog posts that talk about this reachable using Google.– NathanAldenSr
May 13 '16 at 2:07
By the way, creating
HttpClient
instances is expensive. You should reuse instances whenever possible. There are a few blog posts that talk about this reachable using Google.– NathanAldenSr
May 13 '16 at 2:07
add a comment |
3 Answers
3
active
oldest
votes
This code worked for me:
var httpClientHandler = new HttpClientHandler
Proxy = new WebProxy("http://localhost:8888", false),
UseProxy = true
Note that I am not supplying an empty array to my WebProxy
constructor. Perhaps that's the problem?
Removing the string array worked for me too. I had to an entry to HOSTS to get the proxy to work on localhost.
– Casey Burns
Nov 15 '14 at 10:18
1
You just saved my day ^_^
– Wahid Bitar
Mar 17 '17 at 8:04
add a comment |
Ah, The BaseAddress I was pointing to was http://localhost:8081
. Turns out that despite setting BypassOnLocal to false, evidently localhost is still special enough that it bypasses the proxy.
I added a domain binding in IIS, host file entry to point that domain to 127.0.0.1, used newly created domain, now it works.
7
You can also usehttp://localhost.:8888
Notice the magic dot!
– Darrel Miller
May 14 '13 at 0:08
2
I'm getting a Bad Request - Invalid Host Name when I put the . after localhost
– Michael
May 16 '13 at 16:01
@DarrelMiller I get no changes after i add localhost.<system.net> <defaultProxy> <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://localhost.:8888" /> </defaultProxy> </system.net>
– felickz
Aug 25 '14 at 20:51
add a comment |
Is Fiddler configured to capture traffic from all processes? Look at the status bar where you see "Capturing". It should show "All Processes" next to it. If it shows "Web browsers", click it and change it to all processes. This could be different depending on the version of Fiddler you use.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16526689%2fusing-a-proxy-with-net-4-5-httpclient%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
This code worked for me:
var httpClientHandler = new HttpClientHandler
Proxy = new WebProxy("http://localhost:8888", false),
UseProxy = true
Note that I am not supplying an empty array to my WebProxy
constructor. Perhaps that's the problem?
Removing the string array worked for me too. I had to an entry to HOSTS to get the proxy to work on localhost.
– Casey Burns
Nov 15 '14 at 10:18
1
You just saved my day ^_^
– Wahid Bitar
Mar 17 '17 at 8:04
add a comment |
This code worked for me:
var httpClientHandler = new HttpClientHandler
Proxy = new WebProxy("http://localhost:8888", false),
UseProxy = true
Note that I am not supplying an empty array to my WebProxy
constructor. Perhaps that's the problem?
Removing the string array worked for me too. I had to an entry to HOSTS to get the proxy to work on localhost.
– Casey Burns
Nov 15 '14 at 10:18
1
You just saved my day ^_^
– Wahid Bitar
Mar 17 '17 at 8:04
add a comment |
This code worked for me:
var httpClientHandler = new HttpClientHandler
Proxy = new WebProxy("http://localhost:8888", false),
UseProxy = true
Note that I am not supplying an empty array to my WebProxy
constructor. Perhaps that's the problem?
This code worked for me:
var httpClientHandler = new HttpClientHandler
Proxy = new WebProxy("http://localhost:8888", false),
UseProxy = true
Note that I am not supplying an empty array to my WebProxy
constructor. Perhaps that's the problem?
answered Jul 10 '14 at 12:57
NathanAldenSrNathanAldenSr
6,39733045
6,39733045
Removing the string array worked for me too. I had to an entry to HOSTS to get the proxy to work on localhost.
– Casey Burns
Nov 15 '14 at 10:18
1
You just saved my day ^_^
– Wahid Bitar
Mar 17 '17 at 8:04
add a comment |
Removing the string array worked for me too. I had to an entry to HOSTS to get the proxy to work on localhost.
– Casey Burns
Nov 15 '14 at 10:18
1
You just saved my day ^_^
– Wahid Bitar
Mar 17 '17 at 8:04
Removing the string array worked for me too. I had to an entry to HOSTS to get the proxy to work on localhost.
– Casey Burns
Nov 15 '14 at 10:18
Removing the string array worked for me too. I had to an entry to HOSTS to get the proxy to work on localhost.
– Casey Burns
Nov 15 '14 at 10:18
1
1
You just saved my day ^_^
– Wahid Bitar
Mar 17 '17 at 8:04
You just saved my day ^_^
– Wahid Bitar
Mar 17 '17 at 8:04
add a comment |
Ah, The BaseAddress I was pointing to was http://localhost:8081
. Turns out that despite setting BypassOnLocal to false, evidently localhost is still special enough that it bypasses the proxy.
I added a domain binding in IIS, host file entry to point that domain to 127.0.0.1, used newly created domain, now it works.
7
You can also usehttp://localhost.:8888
Notice the magic dot!
– Darrel Miller
May 14 '13 at 0:08
2
I'm getting a Bad Request - Invalid Host Name when I put the . after localhost
– Michael
May 16 '13 at 16:01
@DarrelMiller I get no changes after i add localhost.<system.net> <defaultProxy> <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://localhost.:8888" /> </defaultProxy> </system.net>
– felickz
Aug 25 '14 at 20:51
add a comment |
Ah, The BaseAddress I was pointing to was http://localhost:8081
. Turns out that despite setting BypassOnLocal to false, evidently localhost is still special enough that it bypasses the proxy.
I added a domain binding in IIS, host file entry to point that domain to 127.0.0.1, used newly created domain, now it works.
7
You can also usehttp://localhost.:8888
Notice the magic dot!
– Darrel Miller
May 14 '13 at 0:08
2
I'm getting a Bad Request - Invalid Host Name when I put the . after localhost
– Michael
May 16 '13 at 16:01
@DarrelMiller I get no changes after i add localhost.<system.net> <defaultProxy> <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://localhost.:8888" /> </defaultProxy> </system.net>
– felickz
Aug 25 '14 at 20:51
add a comment |
Ah, The BaseAddress I was pointing to was http://localhost:8081
. Turns out that despite setting BypassOnLocal to false, evidently localhost is still special enough that it bypasses the proxy.
I added a domain binding in IIS, host file entry to point that domain to 127.0.0.1, used newly created domain, now it works.
Ah, The BaseAddress I was pointing to was http://localhost:8081
. Turns out that despite setting BypassOnLocal to false, evidently localhost is still special enough that it bypasses the proxy.
I added a domain binding in IIS, host file entry to point that domain to 127.0.0.1, used newly created domain, now it works.
answered May 13 '13 at 16:34
Mike RuhlinMike Ruhlin
2,85011630
2,85011630
7
You can also usehttp://localhost.:8888
Notice the magic dot!
– Darrel Miller
May 14 '13 at 0:08
2
I'm getting a Bad Request - Invalid Host Name when I put the . after localhost
– Michael
May 16 '13 at 16:01
@DarrelMiller I get no changes after i add localhost.<system.net> <defaultProxy> <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://localhost.:8888" /> </defaultProxy> </system.net>
– felickz
Aug 25 '14 at 20:51
add a comment |
7
You can also usehttp://localhost.:8888
Notice the magic dot!
– Darrel Miller
May 14 '13 at 0:08
2
I'm getting a Bad Request - Invalid Host Name when I put the . after localhost
– Michael
May 16 '13 at 16:01
@DarrelMiller I get no changes after i add localhost.<system.net> <defaultProxy> <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://localhost.:8888" /> </defaultProxy> </system.net>
– felickz
Aug 25 '14 at 20:51
7
7
You can also use
http://localhost.:8888
Notice the magic dot!– Darrel Miller
May 14 '13 at 0:08
You can also use
http://localhost.:8888
Notice the magic dot!– Darrel Miller
May 14 '13 at 0:08
2
2
I'm getting a Bad Request - Invalid Host Name when I put the . after localhost
– Michael
May 16 '13 at 16:01
I'm getting a Bad Request - Invalid Host Name when I put the . after localhost
– Michael
May 16 '13 at 16:01
@DarrelMiller I get no changes after i add localhost.
<system.net> <defaultProxy> <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://localhost.:8888" /> </defaultProxy> </system.net>
– felickz
Aug 25 '14 at 20:51
@DarrelMiller I get no changes after i add localhost.
<system.net> <defaultProxy> <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://localhost.:8888" /> </defaultProxy> </system.net>
– felickz
Aug 25 '14 at 20:51
add a comment |
Is Fiddler configured to capture traffic from all processes? Look at the status bar where you see "Capturing". It should show "All Processes" next to it. If it shows "Web browsers", click it and change it to all processes. This could be different depending on the version of Fiddler you use.
add a comment |
Is Fiddler configured to capture traffic from all processes? Look at the status bar where you see "Capturing". It should show "All Processes" next to it. If it shows "Web browsers", click it and change it to all processes. This could be different depending on the version of Fiddler you use.
add a comment |
Is Fiddler configured to capture traffic from all processes? Look at the status bar where you see "Capturing". It should show "All Processes" next to it. If it shows "Web browsers", click it and change it to all processes. This could be different depending on the version of Fiddler you use.
Is Fiddler configured to capture traffic from all processes? Look at the status bar where you see "Capturing". It should show "All Processes" next to it. If it shows "Web browsers", click it and change it to all processes. This could be different depending on the version of Fiddler you use.
answered May 13 '13 at 16:30
BadriBadri
17k35256
17k35256
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16526689%2fusing-a-proxy-with-net-4-5-httpclient%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is your service under test on your local machine? Consider proxy bypassing for local addresses.
– Xaqron
May 13 '13 at 16:33
By the way, creating
HttpClient
instances is expensive. You should reuse instances whenever possible. There are a few blog posts that talk about this reachable using Google.– NathanAldenSr
May 13 '16 at 2:07