我使用 Flurl 客户端有一个简单的发布请求,我想知道如何使用 IP、端口、用户名和密码等信息使用代理发出此请求。
string result = await atc.Request(url)
.WithHeader("Accept", "application/json")
.WithHeader("Content-Type", "application/x-www-form-urlencoded")
.WithHeader("Host", "www.website.com")
.WithHeader("Origin", "http://www.website.com")
.PostUrlEncodedAsync(new { st = colorID, s = sizeID, qty = 1 })
.ReceiveString();
最佳答案
我正在寻找类似的答案并发现了这个: https://github.com/tmenier/Flurl/issues/228
这是该链接内容的副本。它对我有用!
You can do this with a custom factory:
using Flurl.Http.Configuration; public class ProxyHttpClientFactory : DefaultHttpClientFactory { private string _address; public ProxyHttpClientFactory(string address) { _address = address; } public override HttpMessageHandler CreateMessageHandler() { return new HttpClientHandler { Proxy = new WebProxy(_address), UseProxy = true }; } }
To register it globally on startup:
FlurlHttp.Configure(settings => { settings.HttpClientFactory = new ProxyHttpClientFactory("http://myproxyserver"); });
关于c# - 如何在 Flurl 中使用代理进行 Web 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50649348/