我正在通过.NET的HttpClient调用一个服务错误,尝试通过本地代理(Fiddler)路由请求,但我的代理设置似乎没有生效.
这是我创建客户端的方式:
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;
}
Run Code Online (Sandbox Code Playgroud)
然后我通过以下方式发送请求:
var response = CreateHttpClient(ctx, sid).PostAsJsonAsync("api/prefs/", smp).Result;
Run Code Online (Sandbox Code Playgroud)
请求直接进入服务器而不尝试命中代理.我错过了什么?