Guest User

Untitled

a guest
Mar 16th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.19 KB | None | 0 0
  1.    private string TheRealSharkGet(string url, string proxy, object cookies, string referer, bool followRedirects)
  2.             {
  3.                 HttpWebRequest request = null;
  4.                 HttpWebResponse response = null;
  5.                 string str;
  6.                 try
  7.                 {
  8.                     request = (HttpWebRequest)WebRequest.Create(url);
  9.                     request.Accept = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
  10.                     request.Headers.Add("Accept-Language", "en-us");
  11.                     request.Method = "GET";
  12.  
  13.                     int timeout = 35;
  14.                     if (!string.IsNullOrEmpty(proxy))
  15.                         timeout = 60;
  16.  
  17.                     request.Timeout = timeout * 1000;
  18.                     request.ReadWriteTimeout = timeout * 1000;
  19.                     request.AllowAutoRedirect = followRedirects;
  20.                     request.MaximumAutomaticRedirections = 5;
  21.                     request.KeepAlive = true; //KEEP ALIVE is normally used in webbrowser, it keeps internal socket open for simultaneous calls to the same url... For example: calling mail.yahoo.com, then profile.yahoo.com
  22.  
  23.                     ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
  24.                     if (!string.IsNullOrEmpty(referer))
  25.                         request.Referer = referer;
  26.                     request.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2"; // Latest version of google-chrome user agent
  27.  
  28.                     if (cookies != null)
  29.                     {
  30.                         if(cookies is CookieContainer)
  31.                         {
  32.                             request.CookieContainer = cookies;
  33.                         }
  34.                         else if(cookies is string && !string.IsNullOrEmpty(cookies))
  35.                         {
  36.                             request.Headers.Add("Cookie", cookies.ToString());
  37.                         }
  38.                     }
  39.  
  40.                     if (!string.IsNullOrEmpty(proxy) && proxy.Split(':').Length >= 2)
  41.                     {
  42.                         string[] cp = proxy.Split(':');
  43.                         WebProxy wp = new WebProxy(cp[0] + ":" + cp[1]);
  44.                         if (cp.Length >= 3)
  45.                         {
  46.                             NetworkCredential nc = new NetworkCredential();
  47.                             nc.UserName = cp[2];
  48.                             if (cp.Length >= 4)
  49.                             {
  50.                                 nc.Password = cp[3];
  51.                                 string pauth = Convert.ToBase64String(Encoding.ASCII.GetBytes(nc.UserName + ":" + nc.Password));
  52.                                 request.Headers.Add("Proxy-Authorization", "Basic " + pauth);
  53.                             }
  54.                             request.PreAuthenticate = true;
  55.                             wp.Credentials = nc;
  56.                         }
  57.                         request.Proxy = wp;
  58.                     }
  59.                     else
  60.                     {
  61.                         request.Proxy = null;
  62.                     }
  63.                     response = (HttpWebResponse)request.GetResponse();
  64.                     str = response.Headers + "[ENDHEADERS]";
  65.                     str += new StreamReader(response.GetResponseStream()).ReadToEnd();
  66.                 }
  67.                 catch (System.Net.WebException we)
  68.                 {
  69.                     try
  70.                     {
  71.                         str = we.Response.Headers + "[ENDHEADERS]";
  72.                         str += new StreamReader(we.Response.GetResponseStream()).ReadToEnd();
  73.                     }
  74.                     catch
  75.                     {
  76.                         str = null;
  77.                     }
  78.                 }
  79.                 catch
  80.                 {
  81.                     str = null;
  82.                 }
  83.                 finally
  84.                 {
  85.  
  86.                     if (response != null)
  87.                     {
  88.                         response.Close();
  89.                     }
  90.                 }
  91.                 return str;
  92.             }
  93.         }
Add Comment
Please, Sign In to add comment