PHP发送POST请求
Posted Anyanyamy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP发送POST请求相关的知识,希望对你有一定的参考价值。
<?php
//The url you wish to send the POST request to
$url = 'http://localhost/node/getItem';
//The data you want to send via POST
$fields = [
'item_id' => 3
];
//url-ify the data for the POST
$fields_string = http_build_query($fields);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
echo $result;
?>
参考:https://stackoverflow.com/questions/5647461/how-do-i-send-a-post-request-with-php
以上是关于PHP发送POST请求的主要内容,如果未能解决你的问题,请参考以下文章