How can I send POST data to a URL in PHP (without a form)?
I'm going to use it for sending a variable to complete and submit a form.
How can I send POST data to a URL in PHP (without a form)?
I'm going to use it for sending a variable to complete and submit a form.
you would need 2 forms on your page, one form that posts back to index.php and a second form that posts to paypal
after the first form posts back to index.php, echo javascript in the body tag to submit the paypal form when it loads
<?php
if(isset($_POST['mydatafield'])){
do database stuff
$LOAD = 'document.paypal.submit();';
}
?>
<body onload="<?php echo $LOAD ?>">
<form name="paypal" action="paypal.com?yadayada">
paypal fields
</form>
<form name="myform" action="index.php">
your form stuff
submit button
</form>
Your post data is JSON so use json_decode
to turn it into an array containing anobject and access the object_id
property
$rawPostData = file_get_contents('php://input');
$json = json_decode($rawPostData);
$json = $json[0];
$all = date("F j, Y, g:i a") . " " . $json->object_id. "rn";
file_put_contents("Activity.log", $all, FILE_APPEND);
I just found the solution and yea it was easier than I thought :)
so here is the solution:
string URI = "http://www.myurl.com/post.php";
string myParameters = "param1=value1¶m2=value2¶m3=value3";
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString(URI, myParameters);
}
it works like charm :)
I used:
QByteArray postData;
postData.append("param1=string&");
postData.append("param2=string");
So & instead of newline after each parameter.
If you're looking to post data to a URL from PHP code itself (without using an html form) it can be done with curl. It will look like this:
This will send the post variables to the specified url, and what the page returns will be in $response.