471,355 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 software developers and data experts.

post programmatically

Hi

I want to programmatically perform a post. Can some one please give me
some pointers to which classes I need to use to achieve this?

The form which is normally posted from the website looks like the
following, but I want to do it programmatically.
<form action="https://intl.payments/recdpay" method="POST"
target="_top">
<input type="hidden" name="merchantID" value="xx7223.189" />
<input type="hidden" name="orderID" value="UK_Z0000287" />
<input type="hidden" name="amount" value="59995" />
<input type="hidden" name="currencyCode" value="GBP" />
<input type="hidden" name="cardType" value="6" />
<input type="submit" value="Pay" />
</form>

Thanks,
Peter
Sep 3 '08 #1
3 2164

"Peter" <xd****@hotmail.comwrote in message
news:ux**************@TK2MSFTNGP05.phx.gbl...
Hi

I want to programmatically perform a post. Can some one please give me
some pointers to which classes I need to use to achieve this?

The form which is normally posted from the website looks like the
following, but I want to do it programmatically.
HttpWebRequest should do the trick, just don't forget to set its Method to
"POST". Values of form controls go into the request body, which is just a
stream for WebRequest, so you'll need to format it yourself. W3C HTML 4.01
spec has detailed description of the format:

http://www.w3.org/TR/html4/interact/forms.html#h-17.13
Sep 3 '08 #2
On Sep 3, 6:16*pm, "Peter" <xdz...@hotmail.comwrote:
Hi

I want to programmatically perform a post. Can some one please give me
some pointers to which classes I need to use to achieve this?

The form which is normally posted from the website looks like the
following, but I want to do it programmatically.

<form action="https://intl.payments/recdpay" method="POST"
target="_top">
<input type="hidden" name="merchantID" value="xx7223.189" />
<input type="hidden" name="orderID" value="UK_Z0000287" />
<input type="hidden" name="amount" value="59995" />
<input type="hidden" name="currencyCode" value="GBP" />
<input type="hidden" name="cardType" value="6" />
<input type="submit" value="Pay" />
</form>

Thanks,
Peter
As Pavel Minaev said, HttpWebRequest would be good enough. But
WebRequest is also good, I think. Basically, as far as I know,
HttpWebRequest is a superset of WebRequest. You can find many samples
for it, even the .NET documentation had a section about how to POST a
request at the How do I section.

To save your time, I will write a quick code for you, may contain some
errors, but you can start it from there.

WebRequest req = WebReqest.Create("https://....");
req.Method="POST"; <-Default is GET, so need to specify "POST"
req.ContentType="application/x-www-form-urlencoded"; <-This is
required because there are other types of forms like multipart or
something.
Stream s = req.GetRequestStream();
string data="merchantID=xx7223.189&orderID....";
byte[] binaryData=Encoding.UTF8.GetBytes(data); <-Supposing the page's
encoding is UTF-8. Need to change it in other cases.
s.Write(binaryData,0,binaryData.Length);
s.close();
req.ContentLength=binaryData.Length;
WebResponse res =req.GetResponse();
Sep 3 '08 #3
"Sin Jeong-hun" <ty*******@gmail.comwrote in message
news:1d**********************************@z11g2000 prl.googlegroups.com...
On Sep 3, 6:16 pm, "Peter" <xdz...@hotmail.comwrote:
As Pavel Minaev said, HttpWebRequest would be good enough. But
WebRequest is also good, I think. Basically, as far as I know,
HttpWebRequest is a superset of WebRequest. You can find many samples
for it, even the .NET documentation had a section about how to POST a
request at the How do I section.
WebRequest is an abstract class, HttpWebRequest is one specific
implementation.

It is generally advised to use WebRequest.Create() factory method to
instantiate any implementation of WebRequest. But it is explicitly allowed
to cast the return value of WebRequest.Create() to the specific type you
expect to get.

In this case though, I've missed the fact that WebRequest has property
Method already (strange, since it's really HTTP-specific, and cannot be
properly used in a generic fashion anyway), so no need for cast.
Sep 4 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dan Greenblatt | last post: by
6 posts views Thread by Ben | last post: by
3 posts views Thread by WJ | last post: by
4 posts views Thread by David Veeneman | last post: by
2 posts views Thread by David | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.