php curl vs python GET请求 [英] php curl vs python GET request
本文介绍了php curl vs python GET请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在尝试将python GET请求转换为php curl时遇到问题. 这就是python命令的样子:
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'} )
我正在尝试在php curl中做同样的事情:
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"}
推荐答案
好的,这是对任何有兴趣的人的解决方案,其想法是产生curl命令: curl -GET -d'token = abcdefg'
OK here's the fix for anyone interested, the idea is to produce the curl command: curl -GET -d 'token=abcdefg'
这可以在php curl强制GET中提供发布字段的情况下实现.
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);
这篇关于php curl vs python GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文