我正在解决我通过.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;
}
然后我通过以下方式发送请求:
var response = CreateHttpClient(ctx, sid).PostAsJsonAsync("api/prefs/", smp).Result;
请求直接发送到服务器而不尝试访问代理。我错过了什么?