public static void Test_Handeco_Load_WebRequest_01() { string outputFile = @"test\handeco.html"; string url = "http://www.handeco.org/fournisseurs/rechercher"; string content = "raisonSociale=&SIRET=&departements%5B%5D=03&experience_cotraitance=0&motsCles=&submitRecherche=Rechercher"; //string cookies = "PHPSESSID=572851556c8b3b2ef74692a0b1de6675; __utma=140104362.2125206869.1396505609.1396505609.1396505609.1; __utmc=140104362; __utmz=140104362.1396505609.1.1.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)"; string cookies = "PHPSESSID=572851556c8b3b2ef74692a0b1de6675; __utma=140104362.2125206869.1396505609.1396520128.1396528821.5; __utmb=140104362.1.10.1396528821; __utmc=140104362; __utmz=140104362.1396505609.1.1.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)"; string userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36 CoolNovo/2.0.9.20"; System.Net.WebRequest webRequest = System.Net.WebRequest.Create(url); System.Net.HttpWebRequest httpWebRequest = webRequest as System.Net.HttpWebRequest; httpWebRequest.ServicePoint.Expect100Continue = false; httpWebRequest.UserAgent = userAgent; //httpWebRequest.AutomaticDecompression = System.Net.DecompressionMethods.GZip; httpWebRequest.Method = "POST"; httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; httpWebRequest.Referer = "http://www.handeco.org/fournisseurs/rechercher"; //httpWebRequest.Headers.Add(_requestParameters.headers); System.Net.CookieContainer cookieContainer = new System.Net.CookieContainer(); cookieContainer.zAdd(url, cookies); httpWebRequest.CookieContainer = cookieContainer; // Content-Type: application/x-www-form-urlencoded httpWebRequest.ContentType = "application/x-www-form-urlencoded"; Encoding encoding = Encoding.Default; byte[] bytes = encoding.GetBytes(content); httpWebRequest.ContentLength = bytes.LongLength; System.IO.Stream stream = httpWebRequest.GetRequestStream(); using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(stream)) { w.Write(bytes); } System.Net.WebResponse webResponse = webRequest.GetResponse(); stream = webResponse.GetResponseStream(); System.IO.StreamReader webStream = new System.IO.StreamReader(stream, encoding); string textResult = webStream.ReadToEnd(); outputFile = GetPath(outputFile); zfile.WriteFile(outputFile, textResult); // Connection: keep-alive httpWebRequest.KeepAlive = true; // Cache-Control: max-age=0 // Origin: http://www.handeco.org // Accept-Encoding: gzip,deflate,sdch // Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4 //httpWebRequest.CachePolicy //httpWebRequest.Headers //httpWebRequest.Host }