webrequest POST to HTTPS

M

mammothman42

Hi

Sorry to be posting slabs of code, but i simply can't get this code to
work. I continue to get error 405, method not allowed at
req.GetRequestStream(). Can't for the life of me figure out why, i
mean, of course POSTing is allowed, that's how the site submits the
user data!

WebRequest req =
WebRequest.Create("https://www2.netbank.commbank.com.au/netbank/NetBank/scripts/cgiclnt.dll/CORE-Main Web/ND000_");

byte [] data = null;
data =
System.Text.Encoding.ASCII.GetBytes("EWF_SYS_0=61118042-ff0a-11d0-98df-006097b70359&EWF_FORM_NAME=aBegin&BANK%20ID=CBA&PRODUCT%20NAME=EBS&GROUP=BANKING&LANGUAGE%20ID&USERID=myID&PIN=myPIN&EWFBUTTON&EXTRA3=bankmain&LOGONID=myID&LOGONPIN=myPIN&SUBMIT%20BUTTON=Logon");

req.Method="post";
req.ContentType="application/x-www-form-urlencoded";
req.ContentLength = data.Length;

Stream outputStream = req.GetRequestStream();

outputStream.Write (data, 0, data.Length);

outputStream.Close();

//retrieveFromURL
WebResponse response = req.GetResponse();

Stream responseStream = response.GetResponseStream();

StreamReader reader = new StreamReader(responseStream);
string htmlContent = reader.ReadToEnd();

cheers
Dave
 
M

mammothman42

ok here's some more info: I got the entire bank logon page, copied it
to my own server, filled it out, submitted it, and it gave me exactly
the same error! what on earth is it doing? that is, how did it know
that the submit page was bona fide?

cheers
dave
 
J

Joerg Jooss

Hi

Sorry to be posting slabs of code, but i simply can't get this code to
work. I continue to get error 405, method not allowed at
req.GetRequestStream(). Can't for the life of me figure out why, i
mean, of course POSTing is allowed, that's how the site submits the
user data!

WebRequest req =
WebRequest.Create("https://www2.netbank.commbank.com.au/netbank/NetBank/scripts/cgiclnt.dll/CORE-Main Web/ND000_");

byte [] data = null;
data =
System.Text.Encoding.ASCII.GetBytes("EWF_SYS_0=61118042-ff0a-11d0-98df-006097b70359&EWF_FORM_NAME=aBegin&BANK%20ID=CBA&PRODUCT%20NAME=EBS&GROUP=BANKING&LANGUAGE%20ID&USERID=myID&PIN=myPIN&EWFBUTTON&EXTRA3=bankmain&LOGONID=myID&LOGONPIN=myPIN&SUBMIT%20BUTTON=Logon");

req.Method="post";
req.ContentType="application/x-www-form-urlencoded";
req.ContentLength = data.Length;

Stream outputStream = req.GetRequestStream();

outputStream.Write (data, 0, data.Length);

outputStream.Close();

//retrieveFromURL
WebResponse response = req.GetResponse();

Stream responseStream = response.GetResponseStream();

StreamReader reader = new StreamReader(responseStream);
string htmlContent = reader.ReadToEnd();

You're not processing any cookies. You should use a CookieContainer with
your WebRequests. The site uses cookies.

Cheers,
 
R

Rick Strahl [MVP]

You should probably use:

req.Referer = "https://www2.netbank.commbank.com.au/netbank/bankmain.htm"

instead of explicitly setting the header. I'm guessing that you possibly end
up with two referers in the header which is giving you that error.

In addition it looks like you're POSTing, but you're nto actually sending
data which could be another problem.

BTW, where is that error coming from? THe message you're describing seems
like a server side application message - which could arise from a number of
things dealing with how the form is supposed to be submitted.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
 
Top