次のコードで http プロキシを設定できます。
public class CustomFlurlHttpClient : DefaultHttpClientFactory {
public override HttpClient CreateClient(Url url, HttpMessageHandler m) {
return base.CreateClient(url, CreateProxyHttpClientHandler("http://192.168.0.103:9090"));
}
private HttpClientHandler CreateProxyHttpClientHandler(string proxyUrl, string user = "", string passw = "") {
NetworkCredential proxyCreds = null;
var proxyUri = new Uri(proxyUrl);
proxyCreds = new NetworkCredential (user, passw);
var proxy = new WebProxy (proxyUri, false) {
UseDefaultCredentials = false,
Credentials = proxyCreds
};
var clientHandler = new HttpClientHandler {
UseProxy = true,
Proxy = proxy,
PreAuthenticate = true,
UseDefaultCredentials = false
};
if (user != "" && passw != "") {
clientHandler.Credentials = new NetworkCredential (user, passw);
}
return clientHandler;
}
}
class MainClass {
public static void Main (string[] args) {
run ();
Console.ReadKey ();
}
async static void run() {
using(FlurlClient client = new FlurlClient(c => { c.HttpClientFactory = new CustomFlurlHttpClient();})) {
var result = await client.WithUrl("https://www.google.com").GetStringAsync();
Console.WriteLine(result);
};
}
}
ソックスプロキシではありません。それを行う方法はありますか?または、非同期/待機構文がサポートされている他の(非推奨ではない)残りのクライアント?