I'd like to use PHP to post to a URL the way a form would. Basically the same function that this form would do
<form method="POST" id="foo" action="<?php echo $url; ?>">
<input type="hidden" name="shopId" value="<?php echo $ID; ?>">
<input type="hidden" name="encodedMessage" value="<?php echo $encodedMessage; ?>">
<input type="hidden" name="signature" value="<?php echo $signature; ?>">开发者_StackOverflow;
<input type="submit" value="Submit" name="buy">
</form></div>
How can I do this?
you want to use cURL functions to send an http POST request. For example:
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "name1=val&name2=val2...");
curl_exec($ch);
curl_close($ch);
There's several ways to do this, but the easiest is probably with file_get_contents() and stream_context_create(). See this file_get_contents() comment for an example.
精彩评论