将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 ????
添加它以不验证SSL证书。如果是开发服务器,那很好,如果是生产服务器,则应始终进行验证。
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句