将POST请求发送到某个网站API
function httpPost($url,$params)
{
$ch = curl_init($url);
$contents= json_encode($params);
$access_token='**************************';
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Token ' . $access_token,
'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $contents);
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
$params = file_get_contents('./upload.json');
echo httpPost("https://xxxxx.com/api/v2/review/",$params);
但它无法将POST请求发送到服务器。
Remote Address:[::1]:80
Request URL:http://localhost/publons/submit.php
Request Method:GET
Status Code:500 Internal Server Error
为什么它使用GET,它应该是POST ????
答案 0 :(得分:1)
添加此项以不验证SSL证书。如果它是一个开发服务器,那很好,如果它是生产,虽然这应该总是被验证。
Celluloid