HTTPWEBREQUEST POST with FORM DATA

i analysed the headers sent when i logged in a webpage and see 2 headers , one 302 and one 200
i'm trying to do the same thing that the browse do, but in c# with httpwebrequest i think that was be easy but i'm 2 days trying to do. bellow here is the headers i captured when tried to login and the code that i'm using to simulate the request … i wondering if have someone who can help me , point where is my error and what to do…

REQUEST HEADER WITH CODE 302:

POST http://ift.tt/1CVV5A9 HTTP/1.1 Host: www4.uva.br Proxy-Connection: keep-alive Content-Length: 455 Cache-Control: max-age=0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Origin: http://www4.uva.br User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36 Content-Type: application/x-www-form-urlencoded Referer: http://ift.tt/1CVV5A9 Accept-Encoding: gzip, deflate Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4 Cookie: ASP.NET_SessionId=wlo0ks55tanotwriaraapd55 

WITH FORM DATA :

__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwULLTE4NzU1ODgxNTkPZBYCZg9kFgICAw9kFgICCQ9kFgICAQ9kFgICAQ9kFgICAQ8QZGQWAGQYAQU2Y3RsMDAkRm9ybXVsYXJpb0NvbnRlbnRQbGFjZUhvbGRlciRFc3RhZG9UZWxhTXVsdGlWaWV3Dw9kZmT14eU493cBliuPCSv6TJQbGDKjrA%3D%3D&__VIEWSTATEGENERATOR=7C9DFC57&ctl00%24FormularioContentPlaceHolder%24UsuarioTextBox=@@@@@@&ctl00%24FormularioContentPlaceHolder%24SenhaTextBox=@@@@@&ctl00%24FormularioContentPlaceHolder%24EntrarButton=Entrar 

REQUEST HEADER WITH CODE 200:

POST http://ift.tt/1H3ObyB HTTP/1.1 Host: www4.uva.br Proxy-Connection: keep-alive Content-Length: 32020 Cache-Control: no-cache Origin: http://www4.uva.br X-MicrosoftAjax: Delta=true User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36 Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Accept: */* Referer: http://ift.tt/1H3ObyB Accept-Encoding: gzip, deflate Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4 Cookie: ASP.NET_SessionId=wlo0ks55tanotwriaraapd55; UniversusNet=53956EA1E1E2BB4F86B216AD708DC0160BCAF34768BD4BD9AE0BB6D7AA70A3E6B159AF2A07B653DAC7FD6DA08A7027D3AE6490ADD013ABBFF2318D05EF1DCEF70D05C3FDFDF454EB975971F02E0C61C07200479377919483AF56B2DB4497BBA2C70825F492F5FF7012E97AD357A4440440D1954D6738E6E710B4E705CE4B151A66B3924FD6F9DB4B2305EB5C314D165B29D1C6D0C3EB9C5A9DC398C34458988AFE02735011D809A25E841DD05C9F5647C580BFA911ECFC0AFBE099C1A9CF65C2FDEA986F61AC144929E82DEC00AF0C5C396B2658877350EDB89B38EF08DCC7E4DB42B51E0878EA15E397378381B75EB68AEEE43C066C7C0BB5C7221D1701CF94E70A1B38667FE00A2CAF9E20B1555C75E4C059EAE885DADEF52E332E3DCAFCCD687914FFB517F473DA575798C480DA32550FB3EE3A39F7ACBCCBB60D72E3079B07789FFE3AAD4795E5A6ED2A8663DCC178A2E14A9655F3DD2EF61A04465D01D10EA3B153B1116B5BCD16457C475D325928E3A6F08F8C6C917FAC21660C917543E5A92DD6D1FDC69C90FE02C1F88C5A3DF609153053A6D46DBF1261F77130962D7774DE3275505E05D23EB315A35E32F05FC49AA9629CA5822748103451E45CBDD3555B3C8D70C21C9F19B5BD2AA36FDFB58982E3C6DBE2D3677CD385011252A0D3050CF1B23A025CF541418EC485B7D81DDB182F8E8A06920DCE85B3FAD5D76B5A2F761C 

I MADE THAT CODE TO SIMULATE THIS ACTION:

 HttpWebRequest x = (HttpWebRequest)HttpWebRequest.Create("http://ift.tt/1FSIY8T;); NameValueCollection collection = new NameValueCollection(); NameValueCollection postData = new NameValueCollection(); CookieContainer cookie = new CookieContainer(); ASCIIEncoding ascii = new ASCIIEncoding(); byte[] postBytes = ascii.GetBytes("__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=/wEPDwULLTE4NzU1ODgxNTkPZBYCZg9kFgICAw9kFgICCQ9kFgICAQ9kFgICAQ9kFgICAQ8QZGQWAGQYAQU2Y3RsMDAkRm9ybXVsYXJpb0NvbnRlbnRQbGFjZUhvbGRlciRFc3RhZG9UZWxhTXVsdGlWaWV3Dw9kZmT14eU493cBliuPCSv6TJQbGDKjrA==&__VIEWSTATEGENERATOR=7C9DFC57&ctl00$FormularioContentPlaceHolder$UsuarioTextBox=@@@@&ctl00$FormularioContentPlaceHolder$SenhaTextBox=@@@@@&ctl00$FormularioContentPlaceHolder$EntrarButton=Entrar"); collection.Add("Origin","http://www4.uva.br"); collection.Add("Accept-Language", "pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4"); x.Headers.Add(collection); x.CookieContainer = cookie; x.Method = "POST"; x.ContentType = "application/x-www-form-urlencoded"; x.ContentLength = postBytes.Length; x.Host = "www4.uva.br"; x.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36"; x.AllowAutoRedirect = true; x.Proxy = new WebProxy("http://10.10.10.52:8080", false); x.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials; Stream dataStream = x.GetRequestStream(); // Write the data to the request stream. dataStream.Write(postBytes, 0, postBytes.Length); dataStream.Close(); WebResponse y = x.GetResponse(); var reader = new StreamReader(y.GetResponseStream()); var html = reader.ReadToEnd(); richTextBox1.Text = html.ToString(); 

but the return is the same page i do the request , so what i missing?

by TCPII via /r/csharp

Leave a Reply