這是集成問題。您的幫助是非常感激的(提示||指南)Magento 2 API與Angular 2令牌驗證
我同時在本地安裝了Angular2和Magento2(bitnami)。 Magento conf被改爲擁有CROS的正確頭文件(見下文)。 我從Angular2打電話Magento2獲得令牌和我得到了以下問題:
OPTIONS http://192.168.56.1:82/magento/index.php/rest/V1/integration/admin/token 400(錯誤請求) 的XMLHttpRequest無法加載http://192.168.56.1:82/magento/index.php/rest/V1/integration/admin/token。爲預檢響應具有無效的HTTP狀態代碼400
例外:URL 0:響應與狀態空
角2側:
let headers = new Headers({'Content-type': 'application/json'});
headers.append('Access-Control-Allow-Origin', '*');
headers.append('Access-Control-Allow-Methods', 'GET,POST,OPTIONS,PUT,DELETE');
headers.append('Access-Control-Allow-Headers', 'Origin,Authorization,X-Auth-Token,Accept,Content-Type');
headers.append('Access-Control-Allow-Credentials', 'true');
let options = new RequestOptions({ headers: headers });
return this.http.post('http://192.168.56.1:82/magento/index.php/rest/V1/integration/admin/token',
JSON.stringify('{"username":"angUser", "password":"angUser2017"}'),
options)
.map(res => res.json());
Magento2 API用戶 angUser/angUser2017 消費者鑰匙:5bhvi7gjvyafcp35rajuxh0y4me2plga 消費者祕密:yh1nefyw1u80rd0ip1q6f8pijv9x72f1 訪問令牌:g5plfwth2rhlwtuwfhhqp7mg6sebrxc3 訪問令牌密鑰:i1f4t7j65oo8ydtnteub9xr7wrswe99c
Magento的標題: 響應頭 訪問控制允許的憑據:真 訪問控制允許報頭:起源,內容類型,接受,授權 Access-Control-Allow-Methods:GET,POST,OPTIONS,PUT,DELETE Access-Control-Allow-Origin:*