php卷曲成r httr
我在这方面完全没有经验。我想做的是发送一个 post 请求来访问一个 API,该 API 将返回一个 JSON 文件。
这是PHP中的curl过程:
$url = 'https://app.responseiq.com/apis/reports';
$fields = array('token' => $api_key,
'offset' =>$offset,
'limit' =>$limit,
'widget_id'=>$widget_id
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
$result = curl_exec($ch);
return $result;
这是我到目前为止所得到的,
httr::POST (
url = "https://app.responseiq.com/apis/reports",
query = list (
token = "ABCDEF",
offset =10,
limit =100,
widget_id = "TEST"
),
httr::content_type("application/x-www-form-urlencoded"),
httr::accept("application/json, text/javascript, */*; d=0.2"),
httr::verbose()
)
我没有得到我预期的输出,它应该是JSON格式的数据。 任何帮助将不胜感激。如果我的概念完全错误,如果有人能指导我正确的方向以了解有关使用 httr 包的更多信息,那就太好了。谢谢。
I have totally no experience in this area. What I am trying to do is to send a post request to access an API which would return a JSON file.
This is the curl process in PHP:
$url = 'https://app.responseiq.com/apis/reports';
$fields = array('token' => $api_key,
'offset' =>$offset,
'limit' =>$limit,
'widget_id'=>$widget_id
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
$result = curl_exec($ch);
return $result;
This is what I have so far
httr::POST (
url = "https://app.responseiq.com/apis/reports",
query = list (
token = "ABCDEF",
offset =10,
limit =100,
widget_id = "TEST"
),
httr::content_type("application/x-www-form-urlencoded"),
httr::accept("application/json, text/javascript, */*; d=0.2"),
httr::verbose()
)
I am not getting my expected output, which should be data in JSON format.
Any assistance will be greatly appreciated. If I got my concept totally wrong, it would be great if someone can direct me in the right direction to learn more about using the httr package.Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论