PHP卷曲REST API令牌返回假的Magento 2
问题描述:
我试图让与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)的
答
输出给我下面的错误
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
你可以试试'curl_errno($ CH)'和'curl_error($ CH)'调查,如果'$令牌===感谢FALSE' –
@LorenzoS,没有什么帮助。 –