2017-05-28 93 views
0

我試圖讓與Magento的剩餘2 API的身份驗證令牌與下面的代碼PHP捲曲REST API令牌返回假的Magento 2

$userData = array("username" => "user", "password" => "password"); 
$ch = curl_init("https://domain/index.php/rest/V1/integration/admin/token"); 

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData)); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData)))); 

$token = curl_exec($ch); 
var_dump($token); 

它工作正常,在本地服務器上,而是從$令牌= FALSE測試服務器。我可以從控制檯檢索捲曲的標記。

curl -X POST "https://domain/index.php/rest/V1/integration/admin/token/" -H "Content-Type:application/json" -d '{"username":"user", "password":"password"}' 

爲什麼我在PHP腳本中收到false?有任何想法嗎? curl_error($ CH)的

+1

你可以試試'curl_errno($ CH)'和'curl_error($ CH)'調查,如果'$令牌===感謝FALSE' –

+0

@LorenzoS,沒有什麼幫助。 –

回答

0

輸出給我下面的錯誤

SSL certificate problem: unable to get local issuer certificate 

易修復 - https://stackoverflow.com/a/31830614/923497。只是複製它在這裏

1) Download the latest cacert.pem from https://curl.haxx.se/ca/cacert.pem 

2) Add the following line to php.ini (if this is shared hosting and you don't have access to php.ini then you could add this to .user.ini in public_html) 

curl.cainfo=/path/to/downloaded/cacert.pem