Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private string TheRealSharkGet(string url, string proxy, object cookies, string referer, bool followRedirects)
- {
- HttpWebRequest request = null;
- HttpWebResponse response = null;
- string str;
- try
- {
- request = (HttpWebRequest)WebRequest.Create(url);
- request.Accept = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
- request.Headers.Add("Accept-Language", "en-us");
- request.Method = "GET";
- int timeout = 35;
- if (!string.IsNullOrEmpty(proxy))
- timeout = 60;
- request.Timeout = timeout * 1000;
- request.ReadWriteTimeout = timeout * 1000;
- request.AllowAutoRedirect = followRedirects;
- request.MaximumAutomaticRedirections = 5;
- 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
- ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
- if (!string.IsNullOrEmpty(referer))
- request.Referer = referer;
- 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
- if (cookies != null)
- {
- if(cookies is CookieContainer)
- {
- request.CookieContainer = cookies;
- }
- else if(cookies is string && !string.IsNullOrEmpty(cookies))
- {
- request.Headers.Add("Cookie", cookies.ToString());
- }
- }
- if (!string.IsNullOrEmpty(proxy) && proxy.Split(':').Length >= 2)
- {
- string[] cp = proxy.Split(':');
- WebProxy wp = new WebProxy(cp[0] + ":" + cp[1]);
- if (cp.Length >= 3)
- {
- NetworkCredential nc = new NetworkCredential();
- nc.UserName = cp[2];
- if (cp.Length >= 4)
- {
- nc.Password = cp[3];
- string pauth = Convert.ToBase64String(Encoding.ASCII.GetBytes(nc.UserName + ":" + nc.Password));
- request.Headers.Add("Proxy-Authorization", "Basic " + pauth);
- }
- request.PreAuthenticate = true;
- wp.Credentials = nc;
- }
- request.Proxy = wp;
- }
- else
- {
- request.Proxy = null;
- }
- response = (HttpWebResponse)request.GetResponse();
- str = response.Headers + "[ENDHEADERS]";
- str += new StreamReader(response.GetResponseStream()).ReadToEnd();
- }
- catch (System.Net.WebException we)
- {
- try
- {
- str = we.Response.Headers + "[ENDHEADERS]";
- str += new StreamReader(we.Response.GetResponseStream()).ReadToEnd();
- }
- catch
- {
- str = null;
- }
- }
- catch
- {
- str = null;
- }
- finally
- {
- if (response != null)
- {
- response.Close();
- }
- }
- return str;
- }
- }
Add Comment
Please, Sign In to add comment