Send data using POST method

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
sina_saeedi82
Forum Newbie
Posts: 11
Joined: Sun Aug 23, 2009 5:13 am

Send data using POST method

Post by sina_saeedi82 »

Hi. I'm trying to write a wordpress plugin to contacting with a payment gateway. The gateway is an Iranian bank named Mellat.
First of all I have to send a request to their web-service and they respond me. There are 2 things in response, a string named $RefId and a status. If status be 0 it means every thing is ok and now I redirect customer and send $RefId to bank's gateway using POST method. And then they respond me if payment is ok or not.
I cant send $RefId with POST. How can I do this?

Point: I wrote another payment plugin for another bank named Parsian. The procedure is same but in that case I had to send data using GET method that was so easy. I used this piece of code to redirect using GET method:

Code: Select all

$parsURL = "https://www.pec24.com/pecpaymentgateway/?au=" . $authority ;
header("Location: $parsURL");
exit();
mikeashfield
Forum Contributor
Posts: 159
Joined: Sat Oct 22, 2011 10:50 am

Re: Send data using POST method

Post by mikeashfield »

Code: Select all

<?php
    $parsURL="https://www.pec24.com/pecpaymentgateway/?au=".$authority.;
    header("'Location: ".$parsURL."'");
    exit();
?>
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Send data using POST method

Post by twinedev »

Look up cURL, which basically act like a web browsers that is all done via programming, so you can assign POST data to submit to a site.

-Greg
sina_saeedi82
Forum Newbie
Posts: 11
Joined: Sun Aug 23, 2009 5:13 am

Re: Send data using POST method

Post by sina_saeedi82 »

mikeashfield wrote:

Code: Select all

<?php
    $parsURL="https://www.pec24.com/pecpaymentgateway/?au=".$authority.;
    header("'Location: ".$parsURL."'");
    exit();
?>
The code I inserted, is for another bank that uses GET method. The code is right and works. Now, for another bank, I need to send my data using POST method. It only accepts POST method. How can I send data with POST method in php?
twinedev wrote:Look up cURL, which basically act like a web browsers that is all done via programming, so you can assign POST data to submit to a site.

-Greg
I'm not familiar with cURL. I have to send s.th like this:

Code: Select all

<form method="POST" action="https://pgw.bpm.bankmellat.ir/pgwchannel/startpay.mellat">
<input type="hidden" name="RefId" value="<?php echo $RefId ?>">
</form>
Could you tell me how can I send it using cURL?
mikeashfield
Forum Contributor
Posts: 159
Joined: Sat Oct 22, 2011 10:50 am

Re: Send data using POST method

Post by mikeashfield »

You could also do it with JS too:

Code: Select all

<script language="javascript" version="1.3" type="text/javascript">
function postwith (to,p) {
var myForm = document.createElement("form");
myForm.method="post" ;
myForm.action = to ;
for (var k in p) {
var myInput = document.createElement("input") ;
myInput.setAttribute("name", k) ;
myInput.setAttribute("value", p[k]);
myForm.appendChild(myInput) ;
}
document.body.appendChild(myForm) ;
myForm.submit() ;
document.body.removeChild(myForm) ;
}
</script>
<body onload="postwith('hxtp://urlropost.com',{key:value,key1:value1});">
Post Reply