Advertisement
Guest User

Zachafer

a guest
Sep 11th, 2009
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 24.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Net.Sockets;
  5. using System.Drawing;
  6. using System.Drawing.Imaging;
  7. using System.IO;
  8. using System.Net;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Threading;
  12. using System.Collections;
  13. using System.IO.Compression;
  14. /*
  15. * Author : Zav75
  16. *
  17. * Purpose : This is a Wrapper for HTTP requests
  18. * this was made specially for the site of neopets.com
  19. * This should be useful to make an autobuyer.
  20. *
  21. * Contact me : zavier86@hotmail.com
  22. *
  23. * */
  24. namespace AutoBuyer
  25. {
  26.  
  27.     /// <summary>
  28.     /// This class has as a goal to emulate someone who will navigate in neopet
  29.     /// with firefox. To do it propetly it is needed that we download everything
  30.     /// that firefox download, all the images and javaScripts. Probly this class
  31.     /// can be used for any other site and you would not be seen.
  32.     /// </summary>
  33.     class WrapperHTTP
  34.     {
  35.         static private string _referer = "http://www.neopets.com/hi.phtml";
  36.         static private CookieContainer _cookieJar = null;
  37.         static private bool _isLoggedIn = false;
  38.  
  39.         private struct AcceptHeader
  40.         {
  41.  
  42.             public const String JPG = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,*/*;q=0.8";
  43.             public const String PNG = "image/png,image/*;q=0.8,*/*;q=0.5";
  44.             public const String HTML = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  45.             public const String CSS = "text/css,*/*;q=0.1";
  46.             public const String JS = "*/*";
  47.             public const String PHP = "*/*";
  48.             public const String CAPCHA_SHOW = "image/png,image/*;q=0.8,*/*;q=0.5,en;q=0.3";
  49.             public const String GIF = "image/png,image/*;q=0.8,*/*;q=0.5";
  50.             public const String APP_X_SWF = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  51.         };
  52.  
  53.  
  54.         /// <summary>
  55.         /// Constructor
  56.         /// </summary>
  57.         public WrapperHTTP()
  58.         {
  59.         }
  60.         /// <summary>
  61.         /// This method fake a restocker fast haggling
  62.         /// </summary>
  63.         /// <param name="offer"></param>
  64.         /// <returns></returns>
  65.         static private string smartHaggle(string offer) {
  66.             //ie: offer = 15789
  67.             string newOffer = "";
  68.             string digit = "";
  69.             newOffer = offer.Substring(0,1);// ie :1
  70.             digit = offer.Substring(1, 1);// ie : 5
  71.  
  72.             for (int i = 1; i < offer.Length; i++)
  73.             {
  74.                 newOffer += digit;
  75.  
  76.                 //if the fast gaggling is lower than what the merchant ask
  77.                 if ((int.Parse(newOffer) < int.Parse(offer)) && (i == offer.Length-1))//ie: 15555 < 15789
  78.                 {
  79.                     int tmp =  int.Parse(digit) ;
  80.                     tmp++;
  81.                     digit = tmp.ToString();//we increment the digit
  82.                     i = 0;
  83.                     newOffer = offer.Substring(0, 1);
  84.                 }
  85.             }
  86.  
  87.  
  88.  
  89.             return newOffer;
  90.         }
  91.  
  92.         /// <summary>
  93.         /// This method buys an item from a shop
  94.         /// </summary>
  95.         /// <param name="XY">The coordinnates from the picture</param>
  96.         /// <param name="offer"></param>
  97.         /// <param name="referer"></param>
  98.         /// <returns></returns>
  99.         static public bool buy(string XY, string offer, string referer)
  100.         {
  101.             bool reponse = false;
  102.             int lenght;
  103.             String[] tmp = offer.Split(',');
  104.  
  105.             offer = "";
  106.             for (int p = 0; p < tmp.Length; p++)
  107.                 offer += tmp[p];
  108.  
  109.  
  110.  
  111.             offer = smartHaggle(offer);
  112.             lenght = XY.Length + offer.Length + 14;//current_offer=
  113.             string data = "current_offer=" + offer + XY;
  114.  
  115.             HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.neopets.com/haggle.phtml");
  116.  
  117.  
  118.             request.CookieContainer = _cookieJar;
  119.             request.Method = "POST";
  120.             request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1";
  121.             request.Accept = AcceptHeader.CAPCHA_SHOW;
  122.             request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us,en;q=0.5");
  123.             request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
  124.             request.Headers.Add(HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
  125.             request.Headers.Add(HttpRequestHeader.KeepAlive, "300");
  126.             request.ContentType = "application/x-www-form-urlencoded";
  127.             request.KeepAlive = true;
  128.             request.Referer = "http://www.neopets.com/" + referer;
  129.             request.AllowAutoRedirect = false;
  130.             request.Proxy = null;
  131.  
  132.  
  133.  
  134.             byte[] bytes = Encoding.ASCII.GetBytes(data);
  135.             request.ContentLength = bytes.Length;
  136.             Stream os = request.GetRequestStream();
  137.             os.Write(bytes, 0, bytes.Length);
  138.             os.Close();
  139.  
  140.             //After buying we are redirected to the shop from this url for all shops
  141.             _referer = "http://www.neopets.com/haggle.phtml";
  142.             Console.WriteLine(_referer);
  143.  
  144.             //we get the response from the server
  145.             HttpWebResponse WebResponse = (HttpWebResponse)request.GetResponse();
  146.             //we change the response into a Stream
  147.             Stream responseStream = WebResponse.GetResponseStream();
  148.  
  149.  
  150.             //if we see in the stream gzip it's ziped else it's not
  151.             if (WebResponse.ContentEncoding.ToLower().Contains("gzip"))
  152.                 responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
  153.             else if (WebResponse.ContentEncoding.ToLower().Contains("deflate"))
  154.                 responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
  155.  
  156.             //from the reponse stream we read the html with StreamReader
  157.             StreamReader Reader = new StreamReader(responseStream, Encoding.Default);
  158.             string Html = Reader.ReadToEnd();
  159.  
  160.             if (Html.IndexOf("I accept your offer") != -1)
  161.             {
  162.                 Console.WriteLine("Item bought !");
  163.                 reponse = true;
  164.             }
  165.             else
  166.             {
  167.                 Console.WriteLine("Item missed !");
  168.                 reponse = false;
  169.             }
  170.  
  171.  
  172.             Reader.Close(); // And we close
  173.             Reader = null;
  174.  
  175.             return reponse;
  176.         }
  177.  
  178.  
  179.         static public void connecteToNeopet(string password, string username)
  180.         {
  181.             if (!_isLoggedIn)
  182.             {
  183.                 /*
  184.                   CONSTRUCTION OF THE QUERY
  185.                  */
  186.                 _cookieJar = new CookieContainer();
  187.                 string data = "username=" + username + "&password=" + password + "&destination=%2Fpetcentral.phtml";
  188.                 int content_lenght = data.Length;
  189.                 HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.neopets.com/login.phtml");
  190.                 req.Method = "POST";
  191.                 req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1";
  192.                 req.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us,en;q=0.5");
  193.                 req.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
  194.                 req.Headers.Add(HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
  195.                 req.Headers.Add(HttpRequestHeader.KeepAlive, "300");
  196.                 req.KeepAlive = true;
  197.                 req.ContentType = "application/x-www-form-urlencoded";
  198.                 req.Referer = "http://www.neopets.com/hi.phtml";
  199.                 req.CookieContainer = _cookieJar;
  200.                 req.ContentLength = content_lenght;
  201.                 req.AllowAutoRedirect = false;
  202.                 req.Proxy = null;
  203.  
  204.                 req.Accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
  205.                 _referer = "http://www.neopets.com/hi.phtml";//still hi.phtml yes
  206.                 Console.WriteLine(_referer);
  207.  
  208.                 /*
  209.                  ENCODING POST DATA
  210.                  */
  211.                 byte[] bytes = System.Text.Encoding.ASCII.GetBytes(data);
  212.                 Stream os = req.GetRequestStream();
  213.                 os.Write(bytes, 0, bytes.Length);
  214.                 os.Close();
  215.  
  216.                 /*
  217.                   GETTING THE ANWSER
  218.                  */
  219.                 HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
  220.                 //we change the response into a Stream
  221.                 Stream responseStream = resp.GetResponseStream();
  222.  
  223.  
  224.                 bool connected = false;
  225.                 foreach (Cookie cook in resp.Cookies)
  226.                 {
  227.                     _cookieJar.Add(cook);
  228.                     if (cook.Name.Contains("neologin"))
  229.                         connected = true;
  230.                 }
  231.  
  232.  
  233.  
  234.                 Thread downloadAll = new Thread(new ThreadStart(downloadIndex));
  235.                 downloadAll.Start();
  236.  
  237.                 /*
  238.                  ANALYSING RESULTS
  239.                  */
  240.  
  241.                 //I guesse if we see logout it means we are in ^_^
  242.                 if (connected)
  243.                 {
  244.                     Console.WriteLine("Connection succesful\r\n");
  245.                 }
  246.                 else
  247.                 {
  248.                     Console.WriteLine("You don't have the correct password/username");
  249.                 }
  250.                 _isLoggedIn = true;
  251.             }
  252.             else
  253.             {
  254.  
  255.                 logOut();
  256.                 connecteToNeopet(password, username);
  257.                 _isLoggedIn = true;
  258.             }
  259.         }
  260.  
  261.  
  262.         /// <summary>
  263.         /// This methis log out of neopet
  264.         /// </summary>
  265.         static public void logOut()
  266.         {
  267.  
  268.             /*
  269.             CONSTRUCTION OF THE QUERY TO LOG OUT
  270.             */
  271.             HttpWebRequest request = HTTPqueryMaker("http://www.neopets.com/logout.phtml");
  272.  
  273.             _cookieJar = null;
  274.             _referer = "http://www.neopets.com/hi.phtml";
  275.  
  276.             /*
  277.              GETTING THE ANWSER
  278.             */
  279.             HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
  280.             //we change the response into a Stream
  281.             Stream responseStream = resp.GetResponseStream();
  282.             //if we see in the stream gzip it's ziped else it's not
  283.             if (resp.ContentEncoding.ToLower().Contains("gzip"))
  284.                 responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
  285.             else if (resp.ContentEncoding.ToLower().Contains("deflate"))
  286.                 responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
  287.  
  288.             resp.Close();
  289.             responseStream.Close();
  290.  
  291.         }
  292.  
  293.  
  294.         static private void downloadIndex()
  295.         {
  296.             /*
  297.                CONSTRUCTION OF THE QUERY GO AT THE INDEX http://www.neopets.com/index.phtml
  298.              */
  299.  
  300.             //
  301.             _referer = "http://www.neopets.com/hi.phtml";
  302.             HttpWebRequest request = HTTPqueryMaker("http://www.neopets.com/index.phtml");
  303.             //Here we put referer ready to LogIn()
  304.             _referer = "http://www.neopets.com/index.phtml";
  305.  
  306.  
  307.  
  308.             /*
  309.              GETTING THE ANWSER
  310.             */
  311.             HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
  312.             //we change the response into a Stream
  313.             Stream responseStream = resp.GetResponseStream();
  314.             //if we see in the stream gzip it's ziped else it's not
  315.             if (resp.ContentEncoding.ToLower().Contains("gzip"))
  316.                 responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
  317.             else if (resp.ContentEncoding.ToLower().Contains("deflate"))
  318.                 responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
  319.  
  320.             //from the reponse stream we read the html with StreamReader
  321.             // StreamReader Reader = new StreamReader(responseStream, Encoding.Default);
  322.             // string Html = Reader.ReadToEnd();
  323.  
  324.             responseStream.Close();
  325.             resp.Close();
  326.  
  327.         }
  328.  
  329.  
  330.         /// <summary>
  331.         /// This class is for the Thread downlaodRessources, so we can pass an argument
  332.         /// </summary>
  333.         private class downlaodItems
  334.         {
  335.             string rawHTML;
  336.  
  337.             public downlaodItems(string rawHTML)
  338.             {
  339.                 this.rawHTML = rawHTML;
  340.             }
  341.  
  342.             public void download()
  343.             {
  344.                 downlaodRessources(rawHTML);
  345.             }
  346.  
  347.  
  348.         }
  349.  
  350.  
  351.  
  352.         /// <summary>
  353.         /// This return a html page and download all needed components
  354.         /// </summary>
  355.         /// <param name="url">URL of the html page</param>
  356.         /// <returns>html page in string format</returns>
  357.         static public string downloadPage(string url)
  358.         {
  359.  
  360.             /*
  361.              CONSTRUCTION OF THE QUERY
  362.              */
  363.             HttpWebRequest request = HTTPqueryMaker(url);
  364.  
  365.  
  366.             /*
  367.              GETTING THE ANWSER
  368.             */
  369.             HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
  370.             //we change the response into a Stream
  371.             Stream responseStream = resp.GetResponseStream();
  372.             //if we see in the stream gzip it's ziped else it's not
  373.             if (resp.ContentEncoding.ToLower().Contains("gzip"))
  374.                 responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
  375.             else if (resp.ContentEncoding.ToLower().Contains("deflate"))
  376.                 responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
  377.  
  378.             //from the reponse stream we read the html with StreamReader
  379.             StreamReader Reader = new StreamReader(responseStream, Encoding.Default);
  380.             string Html = Reader.ReadToEnd();
  381.             //Console.WriteLine(Html);
  382.  
  383.             //*** Here we download all the file that usually firefox download ***//
  384.  
  385.             // I created a class so we can call a thread with params
  386.             //and left the unimportant downloads in a thread
  387.             downlaodItems dl = new downlaodItems(Html);
  388.  
  389.             Thread downloadAll = new Thread(new ThreadStart(dl.download));
  390.             downloadAll.Start();
  391.  
  392.  
  393.             responseStream.Close();
  394.             resp.Close();
  395.  
  396.             return Html;
  397.  
  398.  
  399.  
  400.         }
  401.  
  402.         /// <summary>
  403.         /// Download safely the haggle image, but you need to find the image's url and referer on your own
  404.         /// </summary>
  405.         /// <param name="urlImage">
  406.         /// Should look like this :
  407.         /// http://www.neopets.com/captcha_show.phtml?_x_pwned=f199f0ffb046abaf7bba1ed20b231e98
  408.         /// using http://www.neopets.com/captcha_show.phtml alone is not recommanded.      
  409.         /// </param>
  410.         ///
  411.         /// <param name="referer">
  412.         /// Should look like this:
  413.         /// http://www.neopets.com/haggle.phtml?obj_info_id=7432&stock_id=891236737&brr=1366
  414.         /// </param>
  415.         /// <returns>
  416.         ///
  417.         /// </returns>
  418.         static public Bitmap downloadImage(string urlImage,string referer)        {
  419.             try
  420.             {
  421.                 _referer = referer;
  422.                 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlImage);
  423.                 request.CookieContainer = _cookieJar;
  424.                 request.Method = "GET";
  425.                 request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1";
  426.                 request.Accept = "image/png,image/*;q=0.8,*/*;q=0.5,en;q=0.3";
  427.                 request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us,en;q=0.5");
  428.                 request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
  429.                 request.Headers.Add(HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");              
  430.                 request.KeepAlive = true;
  431.                 request.Proxy = null;
  432.                 request.Referer = _referer;
  433.                 request.AllowAutoRedirect = false;
  434.  
  435.  
  436.                 Console.WriteLine("download : " + urlImage + " with " + _referer + "as referer..");
  437.  
  438.                 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  439.                 Stream responseStream = response.GetResponseStream();
  440.  
  441.                 if (response.ContentEncoding.ToLower().Contains("gzip"))
  442.                     responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
  443.                 else if (response.ContentEncoding.ToLower().Contains("deflate"))
  444.                     responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
  445.                
  446.                
  447.                 return new Bitmap(responseStream);
  448.  
  449.             }
  450.             catch (Exception e)
  451.             {
  452.                 Console.WriteLine(e.Message);
  453.                 return null;
  454.             }
  455.         }
  456.  
  457.         /// <summary>
  458.         /// Download all the ressources that firefox usually download from one html document
  459.         /// </summary>
  460.         /// <param name="rawHTML"></param>
  461.         static private void downlaodRessources(string rawHTML)
  462.         {
  463.             int begin = 0;
  464.             int end = 0;
  465.             int numberOfRessources = countOccurence(rawHTML, "src=\"");
  466.             string ressourceLink = "";
  467.  
  468.  
  469.             for (int i = 0; i < numberOfRessources; i++)
  470.             {
  471.                 begin = rawHTML.IndexOf("src=\"", begin) + 5;//src="http://images.neopets.com/n.js"
  472.                 end = rawHTML.IndexOf("\"", begin);
  473.                 int lenght = end - begin;
  474.                 ressourceLink = rawHTML.Substring(begin, lenght);
  475.  
  476.  
  477.                 if (ressourceLink.Contains(".jpg"))
  478.                     downloadRessource(ressourceLink, AcceptHeader.JPG);
  479.                 if (ressourceLink.Contains(".png"))
  480.                     downloadRessource(ressourceLink, AcceptHeader.PNG);
  481.                 if (ressourceLink.Contains(".swf"))
  482.                     downloadRessource(ressourceLink, AcceptHeader.APP_X_SWF);
  483.                 if (ressourceLink.Contains(".html"))
  484.                     downloadHTML(ressourceLink);//html is a special case
  485.                 if (ressourceLink.Contains(".css"))
  486.                     downloadRessource(ressourceLink, AcceptHeader.CSS);
  487.                 if (ressourceLink.Contains(".js"))
  488.                     downloadRessource(ressourceLink, AcceptHeader.JS);
  489.                 if (ressourceLink.Contains(".gif"))
  490.                     downloadRessource(ressourceLink, AcceptHeader.GIF);
  491.                 if (ressourceLink.Contains(".icon"))
  492.                     Console.WriteLine("ICON FOUND !!!");//debug
  493.  
  494.  
  495.             }
  496.  
  497.  
  498.  
  499.         }
  500.         /// <summary>
  501.         /// Count the number of time a patern of string appears in a html file
  502.         /// </summary>
  503.         /// <param name="html"></param>
  504.         /// <returns></returns>
  505.         static private int countOccurence(string html, string patern)
  506.         {
  507.  
  508.             int index = 0;
  509.             int count = 0;
  510.             while (html.IndexOf(patern, index) != -1)
  511.             {
  512.                 index = html.IndexOf(patern, index) + patern.Length; //we add  occurence.Length so we don't while eternity
  513.                 count++;
  514.             }
  515.             return count;
  516.         }
  517.  
  518.         /// <summary>
  519.         ///  Download any file GIF/JPG/ICON/SWF/CSS/JS/GIF
  520.         /// </summary>
  521.         /// <param name="url"></param>
  522.         /// <param name="accept"></param>
  523.  
  524.         static private void downloadRessource(string url, string accept)
  525.         {
  526.  
  527.             /*
  528.              CONSTRUCTION OF THE QUERY
  529.              */
  530.  
  531.             //Here we make a check up so it's a http url
  532.             //else request will throw exceptions
  533.             if (!url.ToLower().Contains("http"))
  534.                 return;
  535.             string temporaryReferer = _referer;
  536.             HttpWebRequest request = HTTPqueryMaker(url);
  537.             _referer = temporaryReferer; //we don't want to change the referer when we download ressources
  538.  
  539.             /*
  540.              GETTING THE ANWSER
  541.             */
  542.             HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
  543.             //we change the response into a Stream
  544.             Stream responseStream = resp.GetResponseStream();
  545.             //if we see in the stream gzip it's ziped else it's not
  546.             if (resp.ContentEncoding.ToLower().Contains("gzip"))
  547.                 responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
  548.             else if (resp.ContentEncoding.ToLower().Contains("deflate"))
  549.                 responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
  550.  
  551.             responseStream.Close();
  552.             resp.Close();
  553.  
  554.  
  555.             //Here we don't really want to use the stuff we downloaded it's just for show.
  556.  
  557.  
  558.         }
  559.  
  560.         /// <summary>
  561.         /// Only Download a html document, just to fake being a true firefox browser
  562.         /// But do not return html document as his public version. This is a useful
  563.         /// method
  564.         /// </summary>
  565.         /// <param name="url"></param>
  566.         static private void downloadHTML(string url)
  567.         {
  568.             /*
  569.               CONSTRUCTION OF THE QUERY
  570.              */
  571.             HttpWebRequest request = HTTPqueryMaker(url);
  572.  
  573.  
  574.  
  575.             HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
  576.             //we change the response into a Stream
  577.             Stream responseStream = resp.GetResponseStream();
  578.  
  579.  
  580.             //if we see in the stream gzip it's ziped else it's not
  581.             if (resp.ContentEncoding.ToLower().Contains("gzip"))
  582.                 responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
  583.             else if (resp.ContentEncoding.ToLower().Contains("deflate"))
  584.                 responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
  585.  
  586.             //from the reponse stream we read the html with StreamReader
  587.             StreamReader Reader = new StreamReader(responseStream, Encoding.Default);
  588.             string Html = Reader.ReadToEnd();
  589.  
  590.             resp.Close();
  591.             responseStream.Close();
  592.  
  593.             downlaodItems dl = new downlaodItems(Html);
  594.             Thread downloadAll = new Thread(new ThreadStart(dl.download));
  595.             downloadAll.Start();
  596.         }
  597.  
  598.  
  599.  
  600.         /// <summary>
  601.         /// This method is used to create a HttpWebRequest Object from a url
  602.         /// </summary>
  603.         /// <param name="url"></param>
  604.         /// <returns></returns>
  605.         static private HttpWebRequest HTTPqueryMaker(string url)
  606.         {
  607.  
  608.             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  609.             request.Method = "GET";
  610.  
  611.             request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1";
  612.             request.Accept = AcceptHeader.HTML;
  613.             request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us,en;q=0.5");
  614.             request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
  615.             request.Headers.Add(HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
  616.             request.Headers.Add(HttpRequestHeader.KeepAlive, "300");
  617.             request.KeepAlive = true;
  618.             request.Referer = _referer;
  619.             request.CookieContainer = _cookieJar;
  620.  
  621.             request.Proxy = null;
  622.             request.AllowAutoRedirect = false;
  623.             Console.WriteLine("download : " + url + " with " + _referer + " as referer..");
  624.             _referer = url;
  625.  
  626.             return request;
  627.  
  628.         }
  629.  
  630.         /// <summary>
  631.         /// Return the actual session via a CookieContainer
  632.         /// </summary>
  633.         /// <returns></returns>
  634.         static public CookieContainer getCookies()
  635.         {
  636.             return _cookieJar;
  637.         }
  638.  
  639.  
  640.     }
  641. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement