【发布时间】:2016-04-29 15:38:29
【问题描述】:
$adminUrl='http://localhost/magento/index.php/rest/V1/integration/admin/token';
$data = array("username" => "myname", "password" => "mypassword");
$data_string = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type=> application/json',
'Content-Length=> ' . strlen($data_string))
);
$token = curl_exec($ch);
print_r($token);
我尝试了上面的代码,但无法获取令牌,而是返回错误消息:
({"message":"服务器无法理解Content-Type HTTP头媒体类型application/x-www-form-urlencoded"},
我该如何解决这个错误?
【问题讨论】: