Send the POST request to some website 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);
but it can't send the POST request to the server.
Remote Address:[::1]:80
Request URL:http://localhost/publons/submit.php
Request Method:GET
Status Code:500 Internal Server Error
Why it use the GET, it should be POST ????
echo httpPost("http://localhost/publons/submit.php",$params);Not having the curl extension installed on your local server would indeed throw an error 500<?php error_reporting(E_ALL); ini_set('display_errors', 1);then the rest of your code, to see if it yields anything.curl_setopt($ch, CURLOPT_POST, 1);withcurl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');but really they do the same thing. As others have suggested. You can also tryecho curl_error($ch);just before you close it to see if there were any errors.