我有一个使用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();
答案 0 :(得分:2)
我正在寻找类似的答案,并发现了这一点:
 https:// github.com/tmenier/Flurl/issues/228


以下是该链接内容的副本。它对我有用!




您可以使用自定义工厂执行此操作:

 
使用Flurl.Http.Configuration;

 
public class ProxyHttpClientFactory:DefaultHttpClientFactory {
 private string _address;



 
public ProxyHttpClientFactory(string address){
 _address = address;
}

 public override HttpMessageHandler CreateMessageHandler(){
返回新的HttpClientHandler {
 Proxy = new WebProxy(_address),
 UseProxy = true
 }
}}

在启动时全局注册

 
FlurlHttp.Configure(settings => {
 settings.HttpClientFactory =
 new ProxyHttpClientFactory(“ http:// myproxyserver “);});