[英]How can I use proxies for web requests in Flurl?
我有一個使用 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
這是該鏈接內容的副本。 它對我有用!
您可以使用自定義工廠執行此操作:
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 }; } }
要在啟動時全局注冊它:
FlurlHttp.Configure(settings => { settings.HttpClientFactory = new ProxyHttpClientFactory("http://myproxyserver"); });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.