POST data to form not working

L

logik3x

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/Ver...2=WRyugA==&C=BRE&E=P&L=FRA&Ref=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(myHttpWebResponse.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.
 
J

Joerg Jooss

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/VerifLogin.ovx?n1=WBuuh3CLOA%
3d%3d&n2=WRyugA%3d%3d&C=BRE&E=P&L=FRA&Ref=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

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(myHttpWebResponse.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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top