我讀了一些Q &但仍然在爲此付出努力。我需要發佈特定的數組到一個API並獲得另一個數組作爲答案。無法使用PHP製作CURL發佈請求
UPDATE
我用:
<?php
echo 'Testing cURL<br>';
// Get cURL resource
$curl = curl_init();
$data=array(array("UserId"=>"xxxx-10100","Password"=>"pass"));
$sendpostdata = json_encode(array("postdata"=> $data));
echo $sendpostdata;
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://cloud.servicebridge.com/api/v1/Login',
CURLOPT_HTTPHEADER => array('Accept: application/json','Content-Type: application/json'),
CURLOPT_USERAGENT => 'Codular Sample cURL Request',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $sendpostdata
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
echo $resp;
// Close request to clear up some resources
curl_close($curl);
?>
這導致
Testing cURL {"postdata":[{"UserId":"xxxxx-10100","Password":"pass"}]} { "Data": null, "Success": false, "Error": { "Message": "Invalid UserId: ", "Value": "InvalidUserId", "Code": 9001 } }
沒有控制檯日誌,沒有其他消息或線索 我想實現這個API https://cloud.servicebridge.com/developer/index#/ 到Worpdress。
的API需要
{ "UserId": "string", "Password": "string" }
你能幫助我嗎?我在做什麼錯
非常欣賞這一點,
Giannis
感謝你的建議。它沒有產生任何錯誤,但它對未來有用的知識 –
的事情是,當我在API測試網站https://cloud.servicebridge.com/developer/index#/中使用完全相同的字符串時,它們工作。我只是複製粘貼。還有什麼其他的東西 –
以及響應體中的''Data「:null」'是什麼意思?你認爲它是相關的嗎? –