0

我在 PHP 中使用 cURL 来访问 Asana API。

我很高兴将我的值作为 GET 附加到 URL,但现在,随着我的应用程序变大,我发布的数据越来越多,所以我一直在尝试将其转换为发布。

到目前为止,我已经尝试过:

setting post['data'] to a json object {key:value,key:value}
setting post['data'] to a json object {options:{key:value,key:value}}
setting post['data'] to a json object {data:{options:{key:value,key:value}}}
setting post['data'] to a json object {data:{key:value,key:value}}
setting post['body'] to all of the above json objects

到目前为止,对于我的方法,我最终得到了错误:

Could not parse request data, invalid JSON

当然,使用 cURL,我正在这样做:

$post = json_encode($myFields);
curl_setopt(CURLOPT_POSTFIELDS,array('data'=>$post));

对于所有这些测试,我将输出 JSON 并使用 JSLint 对其进行验证。这是非常有效的 JSON,所以问题绝对不是那个。我只需要知道为什么它无效。

我只是不能让它工作。感谢您的帮助-丹尼尔。

4

2 回答 2

3

我为 Asana API 制作了一个 PHP 类包装器。你可以在这里抓住它:https ://github.com/ajimix/asana-api-php-class

于 2012-05-19T08:45:55.603 回答
0

尝试在 JSON 中编码所有数组,而不仅仅是“数据”部分:

$post = json_encode(array('data' => $myFields));
curl_setopt(CURLOPT_POSTFIELDS, $post); 
于 2012-04-30T10:33:13.233 回答