【发布时间】:2016-02-14 06:57:15
【问题描述】:
嗨,我正在尝试使用 pushbots api 来获取我的应用程序的分析。问题是我不太了解 curl 或如何实现它。
我希望有人能解释我如何使用我在下面粘贴的代码。
curl -X GET \
-H "x-pushbots-appid: xxxxxxxxxxxxxxxxxxxxxxx" \
-H "x-pushbots-secret: xxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
https://api.pushbots.com/analytics
编辑: 我现在正在使用代码
<?php
$headers = array("Content-Type: application/json","x-pushbots-appid: XXXXXXXXXXXXXX","x-pushbots-secret: XXXXXXXXXXXXXXXXXXXXXX");
$appid = "x-pushbots-appid: XXXXXXXXXXXXXXXXXXXXXXXXX";
$secretid = "x-pushbots-secret: XXXXXXXXXXXXXXXXXXXXXXX";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"api.pushbots.com/analytics");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $appid&$secretid);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//set the headers now
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec($ch);
curl_close ($ch);
var_dump($output);
?>
我现在收到这个错误:
string(64) "{"code":"MethodNotAllowedError","message":"POST is not allowed"}"
【问题讨论】:
-
好的,从我可以理解的问题中,您想要解释您的代码以及如何使用它。 Stackoverflow 不是我想回答这个问题的地方。看看 Code Review,就像它的名字说它是一个代码审查网站一样,也许使用该网站的人可以深入解释它。
-
嗨@CollinKoornstra 我很感激你试图提供帮助,但这个问题完全是代码审查的题外话。 CR 的黄金法则是代码必须已经按预期工作。解释/修复代码不是我们所做的(它准确地是 SO 的用途)。您可能想阅读A Guide to CR for Stack Overflow Users