Guest User

Untitled

a guest
Sep 20th, 2017
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Threading.Tasks;
  4. using System.Net.Http;
  5. using System.Net;
  6. using System.Collections.Generic;
  7.  
  8.  
  9. namespace CrawleraSample
  10. {
  11. class program
  12. {
  13. static void Main()
  14. {
  15. Task t = new Task(HTTP_GET);
  16. t.Start();
  17. Console.ReadLine();
  18. }
  19.  
  20. static async void HTTP_GET()
  21. {
  22. var TARGETURL = "https://www.redfin.com/stingray/do/login";
  23.  
  24. NetworkCredential proxyCreds = new NetworkCredential("APIKEY:", "");
  25.  
  26. WebProxy proxy = new WebProxy("proxy.crawlera.com:8010", false)
  27. {
  28. Credentials = proxyCreds,
  29. };
  30.  
  31. HttpClientHandler handler = new HttpClientHandler()
  32. {
  33. Proxy = proxy,
  34. UseProxy = true,
  35. UseDefaultCredentials = false,
  36. PreAuthenticate = true,
  37. AllowAutoRedirect = false,
  38. };
  39.  
  40. ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
  41.  
  42. var username = "brucedeli@juno.com";
  43. var password = "Doeadeer1";
  44. var formContent = new FormUrlEncodedContent(new[]
  45. {
  46. new KeyValuePair<string, string>("email_input", username),
  47. new KeyValuePair<string, string>("password_input", password),
  48. });
  49.  
  50. Console.WriteLine("GET: + " + TARGETURL);
  51.  
  52. // ... Use HttpClient.
  53. HttpClient client = new HttpClient(handler);
  54.  
  55. client.DefaultRequestHeaders.Add("Accept-Language", "en-US,en;q=0.8,es;q=0.6");
  56. client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br");
  57. client.DefaultRequestHeaders.Add("Referer", "https://www.redfin.com/stingray/do/login?redirect-path=%2F");
  58. client.DefaultRequestHeaders.Add("Host", "www.redfin.com");
  59. client.DefaultRequestHeaders.Add("X-Crawlera-Session", "<session_id>");
  60.  
  61. // ... ignore this
  62. //var byteArray = Encoding.UTF8.GetBytes("APIKEY:");
  63. //client.DefaultRequestHeaders.ProxyAuthorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
  64.  
  65. HttpResponseMessage response = await client.PostAsync(TARGETURL, formContent);
  66. HttpContent content = response.Content;
  67.  
  68. // ... Check Status Code
  69. Console.WriteLine("Response StatusCode: " + (int)response.StatusCode);
  70.  
  71. // ... Read the string.
  72. string result = await content.ReadAsStringAsync();
  73.  
  74. // ... Display the result.
  75. Console.WriteLine("\nResponse Body: \n" + result);
  76. }
  77. }
  78. }
Add Comment
Please, Sign In to add comment