470,628 Members | 2,315 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,628 developers. It's quick & easy.

POST data to form not working

I'm developping a program to automate the submisson of grades to a
website called omnivox.ca (http://brebeuf.omnivox.ca). My problem is
that I can't get the login working. I get the cookie right and the post
data is corect. But when I sniff the http packet it contains not post
data and he response is not the same. Here are the sniffed post
packets.

POST from IE6
(Request-Line):POST
/Estd/Default.aspx?C=BRE&E=P&L=FRA&Ref=20051122161245 HTTP/1.1
Accept:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*
Referer:https://brebeuf.omnivox.ca/Estd/Default.aspx?
Accept-Language:en-ca
Content-Type:application/x-www-form-urlencoded
Accept-Encoding:gzip, deflate
User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET
CLR 2.0.50727; .NET CLR 1.1.4322)
Host:brebeuf.omnivox.ca
Content-Length:44
Connection:Keep-Alive
Cache-Control:no-cache
Cookie:comn=BRE; lngomn=FRA
RESPONSE
(Status-Line):HTTP/1.1 302 Found
Date:Tue, 22 Nov 2005 21:28:02 GMT
Server:Microsoft-IIS/6.0
X-Powered-By:ASP.NET
X-AspNet-Version:1.1.4322
Location:https://brebeuf.omnivox.ca/estd/Veri...20051122162802
Set-Cookie:comn=BRE; expires=Wed, 22-Nov-2006 21:28:02 GMT; path=/
Set-Cookie:lngomn=FRA; expires=Wed, 22-Nov-2006 21:28:02 GMT; path=/
Cache-Control:private
Content-Type:text/html; charset=iso-8859-1
Content-Length:254

POST from csharp
(Request-Line):POST
/Estd/Default.aspx?C=BRE&E=P&L=FRA&Ref=20051122161245 HTTP/1.1
Content-Type:application/x-www-form-urlencoded
User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET
CLR 2.0.50727; .NET CLR 1.1.4322)
Host:brebeuf.omnivox.ca
Cookie:comn=BRE; lngomn=FRA
Content-Length:44
Expect:100-continue
RESPONSE
(Status-Line):HTTP/1.1 100 Continue

Here is my code:

string uri = "http://brebeuf.omnivox.ca/";
HttpWebRequest myHttpWebRequest =
(HttpWebRequest)WebRequest.Create(uri);
myHttpWebRequest.CookieContainer = new CookieContainer();
HttpWebResponse myHttpWebResponse =
(HttpWebResponse)myHttpWebRequest.GetResponse();
myHttpWebResponse.Close();
string postData =
"formEtudiant=o&NoDA=000000&NIP=PASS&x=0&y=0";
byte[] byte1 = Encoding.UTF8.GetBytes(postData);
HttpWebRequest myHttpWebRequest2 =
(HttpWebRequest)WebRequest.Create(myHttpWebRespons e.ResponseUri);
myHttpWebRequest2.ContentType =
"application/x-www-form-urlencoded";
myHttpWebRequest2.ContentLength = postData.Length;
myHttpWebRequest2.Method = "POST";
myHttpWebRequest2.CookieContainer =
myHttpWebRequest.CookieContainer;
myHttpWebRequest2.AllowAutoRedirect = true;
Stream newStream = myHttpWebRequest2.GetRequestStream();
newStream.Write(byte1, 0, byte1.Length);
newStream.Close();

I really don't get why it isn't working, please help me out I need to
finish this soon. If any other informations is need ask for it. Thank
you in advance.

Nov 24 '05 #1
1 2986
lo*****@gmail.com wrote:
I'm developping a program to automate the submisson of grades to a
website called omnivox.ca (http://brebeuf.omnivox.ca). My problem is
that I can't get the login working. I get the cookie right and the
post data is corect. But when I sniff the http packet it contains not
post data and he response is not the same. Here are the sniffed post
packets.

POST from IE6
(Request-Line):POST
/Estd/Default.aspx?C=BRE&E=P&L=FRA&Ref=20051122161245 HTTP/1.1
Accept:image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*
Referer:https://brebeuf.omnivox.ca/Estd/Default.aspx?
Accept-Language:en-ca
Content-Type:application/x-www-form-urlencoded
Accept-Encoding:gzip, deflate
User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
.NET CLR 2.0.50727; .NET CLR 1.1.4322)
Host:brebeuf.omnivox.ca
Content-Length:44
Connection:Keep-Alive
Cache-Control:no-cache
Cookie:comn=BRE; lngomn=FRA
RESPONSE
(Status-Line):HTTP/1.1 302 Found
Date:Tue, 22 Nov 2005 21:28:02 GMT
Server:Microsoft-IIS/6.0
X-Powered-By:ASP.NET
X-AspNet-Version:1.1.4322
Location:https://brebeuf.omnivox.ca/estd/Veri...n1=WBuuh3CLOA%
3d%3d&n2=WRyugA%3d%3d&C=BRE&E=P&L=FRA&Ref=20051122 162802
Set-Cookie:comn=BRE; expires=Wed, 22-Nov-2006 21:28:02 GMT; path=/
Set-Cookie:lngomn=FRA; expires=Wed, 22-Nov-2006 21:28:02 GMT; path=/
Cache-Control:private Content-Type:text/html; charset=iso-8859-1
Content-Length:254

POST from csharp
(Request-Line):POST
/Estd/Default.aspx?C=BRE&E=P&L=FRA&Ref=20051122161245 HTTP/1.1
Content-Type:application/x-www-form-urlencoded
User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
.NET CLR 2.0.50727; .NET CLR 1.1.4322)
Host:brebeuf.omnivox.ca
Cookie:comn=BRE; lngomn=FRA
Content-Length:44
Expect:100-continue
RESPONSE
(Status-Line):HTTP/1.1 100 Continue
Your HTTP capture shouldn't end here. The question is: Does it end here?
Here is my code:

string uri = "http://brebeuf.omnivox.ca/";
HttpWebRequest myHttpWebRequest =
(HttpWebRequest)WebRequest.Create(uri);
myHttpWebRequest.CookieContainer = new CookieContainer();
HttpWebResponse myHttpWebResponse =
(HttpWebResponse)myHttpWebRequest.GetResponse();
myHttpWebResponse.Close();
string postData =
"formEtudiant=o&NoDA=000000&NIP=PASS&x=0&y=0";
byte[] byte1 = Encoding.UTF8.GetBytes(postData);
HttpWebRequest myHttpWebRequest2 =
(HttpWebRequest)WebRequest.Create(myHttpWebRespons e.ResponseUri);
myHttpWebRequest2.ContentType =
"application/x-www-form-urlencoded";
myHttpWebRequest2.ContentLength = postData.Length;
myHttpWebRequest2.Method = "POST";
myHttpWebRequest2.CookieContainer =
myHttpWebRequest.CookieContainer;
myHttpWebRequest2.AllowAutoRedirect = true;
Stream newStream = myHttpWebRequest2.GetRequestStream();
newStream.Write(byte1, 0, byte1.Length);
newStream.Close();


Why do fetch a page before logging in? That shouldn't be necessary.

--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 25 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by TG | last post: by
24 posts views Thread by moriman | last post: by
15 posts views Thread by tmax | last post: by
8 posts views Thread by Laith Zraikat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.