Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. public class CustomFlurlHttpClient : DefaultHttpClientFactory {
  2. public override HttpClient CreateClient(Url url, HttpMessageHandler m) {
  3. return base.CreateClient(url, CreateProxyHttpClientHandler("http://192.168.0.103:9090"));
  4. }
  5.  
  6. private HttpClientHandler CreateProxyHttpClientHandler(string proxyUrl, string user = "", string passw = "") {
  7. NetworkCredential proxyCreds = null;
  8. var proxyUri = new Uri(proxyUrl);
  9. proxyCreds = new NetworkCredential (user, passw);
  10. var proxy = new WebProxy (proxyUri, false) {
  11. UseDefaultCredentials = false,
  12. Credentials = proxyCreds
  13. };
  14. var clientHandler = new HttpClientHandler {
  15. UseProxy = true,
  16. Proxy = proxy,
  17. PreAuthenticate = true,
  18. UseDefaultCredentials = false
  19. };
  20. if (user != "" && passw != "") {
  21. clientHandler.Credentials = new NetworkCredential (user, passw);
  22. }
  23. return clientHandler;
  24. }
  25. }
  26. class MainClass {
  27. public static void Main (string[] args) {
  28. run ();
  29. Console.ReadKey ();
  30. }
  31.  
  32. async static void run() {
  33. using(FlurlClient client = new FlurlClient(c => { c.HttpClientFactory = new CustomFlurlHttpClient();})) {
  34. var result = await client.WithUrl("https://www.google.com").GetStringAsync();
  35. Console.WriteLine(result);
  36. };
  37. }
  38. }
  39.  
  40. public override HttpClient CreateClient(Url url, HttpMessageHandler m)
  41. {
  42. var socksProxy = new Socks5ProxyClient("127.0.0.1", 9150);
  43. var handler = new ProxyHandler(socksProxy);
  44. return base.CreateClient(url, handler);
  45. }
  46.  
  47. public class CustomFlurlHttpClient : DefaultHttpClientFactory
  48. {
  49. public override HttpMessageHandler CreateMessageHandler() {
  50. var socksProxy = new Socks5ProxyClient("127.0.0.1", 9150);
  51. return new ProxyHandler(socksProxy);
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement