我无法将命令行 cURL 转换为 php cURL。我已阅读有关此主题的其他链接,但仍然卡住,希望能提供任何帮助。
我正在尝试将网络表单中的联系信息自动放入在线 CRM 中。
API 信息: http: //karmacrm.zendesk.com/entries/23648323-Contacts
我的代码:
$header = array('contact[first_name]=aaaaaaa','API-KEY: XXXXXXXXX');
$pageurl = "https://app.karmacrm.com/api/v2/contacts.json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $pageurl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERPWD, 'mXXXX@gmail.com:7iNXXXXXXXXXX');
curl_setopt($ch, CURLOPT_HEADER, TRUE); // -i
curl_setopt($ch, CURLOPT_VERBOSE, TRUE); // -v
curl_setopt($ch, CURLOPT_CUSTOMEREQUEST, "POST"); //-X
curl_setopt($ch, CURLOPT_BINARYTRANSFER, FALSE); // --data-binary, -d
$output = curl_exec($ch);
curl_close($ch);
echo $output;
响应:
HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 401
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11
Strict-Transport-Security: max-age=31536000
X-UA-Compatible: IE=Edge,chrome=1
Cache-Control: no-cache, private
X-Request-Id: 8d9397e1c2d43580db7XXXXXXXXXXXX
X-Runtime: 0.004153
Date: Wed, 24 Apr 2013 03:14:27 GMT
X-Rack-Cache: miss
Server: nginx/1.2.3 + Phusion Passenger 3.0.11 (mod_rails/mod_rack)
{"error":"You need to sign in or sign up before continuing."}1
感谢您的帮助,我很感激。