我在将cURL转换为PHP cURL时遇到了一些小问题。
cURL是:
curl -X POST https://api.curated.co/PUBLICATION_KEY/api/v1/email_subscribers -H 'Accept: application/json' -H 'Content-type: application/json' -H 'Authorization: Token token="API_KEY"' -d '{ "email" : "new_subscriber@example.com" }'我把它转换成:
<?php
$headers = array(
'Accept: application/json',
'Content-type: application/json',
'Authorization: Token token="API_KEY"'
);
$data = array("email" => "new_subscriber@example.com");
$data_string = json_encode($data);
$ch = curl_init('https://api.curated.co/PUBLICATION_KEY/api/v1/email_subscribers');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
?>但我没有得到任何回应。注意:,我正在用适当的API_KEY和PUBLICATION_KEY来改变我的API_KEY和PUBLICATION_KEY。
我正在遵循以下指南:http://support.curated.co/hc/en-us/articles/201753981-Adding-Subscribers-with-the-API
如果我遗漏了什么你能告诉我吗?
发布于 2015-02-11 20:12:46
如果没有任何改变,我肯定会用curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");替换curl_setopt($ch, CURLOPT_POST, true);,您也可能希望添加curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);,以防策划者涉及重定向(可能他们有一个单独的auth层,然后将您转发到所需的端点)。
https://stackoverflow.com/questions/28463261
复制相似问题