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();