Filling in HttpWebRequest object with form data

G

Guest

I am looking to post to a banking site form data in process to do with a checkout

I see that the HttpWebRequest object can befilled with header information and form data so that programmatically i can post form data and then process the HttpWebResponse however, I cannot find any examples of how to fill that object with the form data I need to submit

Does anyone know of any site listing example strings of form data so that I can see how to post the name/value pairs

Much thank
Erik
 
B

bruce barker

the post data format is:

<fieldName>=<value>&<fieldName>=<value>

the value should be url encoded, not html or xml.

example:

value1=hello&value2=hello%20there

be sure to set the header type form encoded

-- bruce (sqkwork.com)


Erik Jensen said:
I am looking to post to a banking site form data in process to do with a checkout.

I see that the HttpWebRequest object can befilled with header information
and form data so that programmatically i can post form data and then process
the HttpWebResponse however, I cannot find any examples of how to fill that
object with the form data I need to submit.
Does anyone know of any site listing example strings of form data so that
I can see how to post the name/value pairs?
 
G

Guest

Thanks. So to clarify. If i were to write something like the following, would that be on the right track

string postData="FirstFormField=" + FirstFormVariable +"&SecondFormField=" + SecondFormFiel
ASCIIEncoding encoding=new ASCIIEncoding()
byte[] byte1=encoding.GetBytes(postData)

myHttpWebRequest.ContentType="application/x-www-form-urlencoded"

myHttpWebRequest.ContentLength=postData.Length
Stream newStream=myHttpWebRequest.GetRequestStream()

//Then parse the response somehow
 
B

bruce barker

almost:

string postData = string.Format("FirstFormField={0}&SecondFormField={1}",
HttpUtility.UrlEncode(FirstFormField),
HttpUtility.UrlEncode(SecondFormField));

the response will be returned html, that you need to parse.

-- bruce (sqlwork.com)



Erik Jensen said:
Thanks. So to clarify. If i were to write something like the following,
would that be on the right track?
string postData="FirstFormField=" + FirstFormVariable +"&SecondFormField=" + SecondFormField
ASCIIEncoding encoding=new ASCIIEncoding();
byte[] byte1=encoding.GetBytes(postData);

myHttpWebRequest.ContentType="application/x-www-form-urlencoded";

myHttpWebRequest.ContentLength=postData.Length;
Stream newStream=myHttpWebRequest.GetRequestStream();

//Then parse the response somehow?
 

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

Similar Threads


Members online

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top