Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Text;
- namespace FiddlerRequestToCodePlus
- {
- public static class ClonedWebRequest
- {
- //Calls request functions sequentially.
- static ClonedWebRequest()
- {
- HttpWebResponse response;
- if (Request_www_google_com(out response))
- {
- //Success, possibly use response.
- response.Close();
- }
- else
- {
- //Failure, cannot use response.
- }
- }
- /// <summary>
- /// Tries to request the URL: http://www.google.com/
- /// </summary>
- /// <param name="response">After the function has finished, will possibly contain the response to the request.</param>
- /// <returns>True if the request was successful; false otherwise.</returns>
- static bool Request_www_google_com(out HttpWebResponse response)
- {
- response = null;
- try
- {
- //Create request to URL.
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com/");
- //Set request headers.
- request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8";
- request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json";
- request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-us,en;q=0.5");
- request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
- request.Headers.Set(HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
- request.Headers.Add("Keep-Alive", "115");
- request.KeepAlive = true;
- request.Headers.Set(HttpRequestHeader.Cookie, @"PREF=ID=095864ae848ee5d3:U=338ba9bb0fe625b3:LD=en:NR=100:CR=2:TM=1283685796:LM=1283685796:GM=1:IG=3:S=D3-ZdATPqAvDPjcz; NID=38=1GeLw2zOceGNIzkneGS8biUaVyUiqzQM8tC-407Wy3GmGH_p_IaLgyxV0Rw0htvD8r-Qs6CHJ3LtrvlJjT-frFyZiiAJU_Zx5ZBdDW-nDQyvR78qX3ZXLI9woRqNPbUb; rememberme=true; SID=DQAAAJUAAACVkDK_0mGPIRbFONToK5IieAA_IfWamNG30p6_Q7FvO8h6HmiVu0Ns5O1isWvVmr7i7BUT7AURN2W_qwsLIPtoWgPrc1Ke4grNdIQ4t5ZWqDY804PT4L3RG2k8dG6L9mlko82aDTyhaIbLtpKEJIEAQ8J3TLm1qyiuJERFEjqSd8jyUC2yfTtSMmIjWY9QK2lQEKtsDEoUJn1zI5VERuHx; HSID=AaUcLGhxqvs_nq4eA; TZ=420");
- //Get response to request.
- response = (HttpWebResponse)request.GetResponse();
- }
- catch (WebException e)
- {
- //ProtocolError indicates a valid HTTP response, but with a non-200 status code (e.g. 304 Not Modified, 404 Not Found)
- if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
- else return false;
- }
- catch (Exception)
- {
- if(response != null) response.Close();
- return false;
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement