php卷曲成r httr

发布于 2025-01-19 14:11:51 字数 1049 浏览 3 评论 0原文

我在这方面完全没有经验。我想做的是发送一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文