问题
I have an issue trying to convert a python GET request to php curl. This is what the python command looks like :
requests.get( f'{url}/report', data={'token': reporting_token, 'format': 'pdf'} )
I'm trying to do the same thing in php curl :
$ch = curl_init();
$params = array(
'token'=>'abcdefgh',
'format'=>'pdf',
)
$url = $url.'?'.http_build_query($params); //this shows http://xxx/report?token=abcdefgh&format=pdf
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
This couldn't be any simpler, however I am getting the following error :
{"message":"missing parameter : token"}
回答1:
OK here's the fix for anyone interested, the idea is to produce the curl command: curl -GET -d 'token=abcdefg'
This can be achieved in php curl forcing a GET providing post fields...
curl_setopt($ch, CURLOPT_POSTFIELDS, $get);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_URL, $url);
来源:https://stackoverflow.com/questions/58792670/php-curl-vs-python-get-request