.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;
要求は、プロキシをヒットしようとせずにサーバーに直接送信されます。私は何を取りこぼしたか?