我是新的PHP捲曲......我只是想知道如何把這個curl命令到PHP:捲曲與陣列PHP,也許簡單的答案
curl https://ancient-test.chargebee.com/api/v1/portal_sessions \
-u test_rdsfgfgfddsffds: \
-d customer[id]="EXAMPLE" \
-d redirect_url="https://yourdomain.com/users/3490343"
現在我已經得到了:
$post_data['customer']['id'] = "EXAMPLE";
$post_data['redirect_url'] = "http://" . SITE_URL . "/myaccount/";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://ancient-test.chargebee.com/api/v1/portal_sessions");
curl_setopt($ch,CURLOPT_USERPWD,"test_rdsfgfgfddsffds:");
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
$output = curl_exec($ch);
curl_close($ch);
但我得到的錯誤信息:
{ 「錯誤」:[{ 「消息」: 「有在提交錯誤」},{ 「參數」:「顧客[ID ]「,」消息「:」不能是bla nk「}]}
感謝您的幫助!
月
是'$ customer ['id']'empty? – Kisaragi
您是否在項目中使用了Doctrine? – Tobias
php的curl擴展不處理多維數組(afaik)。您應該使用'curl_setopt($ ch,CURLOPT_POSTFIELDS,http_build_query($ post_data));'或手動創建第一維數組鍵。但是,您當前的代碼應該生成一個數組到字符串的轉換警告。你確定顯示的代碼是你測試的代碼嗎? – Rangad