MobileFIrst& Magento Consumer无权访问%资源REST API

时间:2016-03-21 13:43:11

标签: ibm-mobilefirst magento2 mobilefirst-adapters

我在我的适配器中的MobileFIrst项目(Worcklight)中使用MAGENTO 2 REST API:

function _retrieve(token) { 
    if (!token)
        return { 'isSuccessful': false, 'errorMsg' : 'params is ' + params};
    var authtok = "Bearer "+ token;
    var input = {
        method : 'get',
        returnedContentType : 'json',
        path : 'rest/default/V1/categories/41/products',
        parameters: { },
        headers: {"Accept":"application\/json", "Authorization":authtok} 
    };
    return WL.Server.invokeHttp(input);
}

得到这个结果:

{"message":"Consumer is not authorized to access %resources","statusCode":401,"isSuccessful":true,"statusReason":"Unauthorized","parameters":{"resources":"self"},"responseHeaders":{"Content-Length":"95","Expires":"Thu, 19 Nov 1981 08:52:00 GMT","X-XSS-Protection":"1; mode=block","Connection":"Keep-Alive","Server":"Apache\/2.4.17 (Win32) OpenSSL\/1.0.2d PHP\/5.6.15","X-Powered-By":"PHP\/5.6.15","Cache-Control":"no-store, no-cache, must-revalidate, post-check=0, pre-check=0","Pragma":"no-cache","X-Content-Type-Options":"nosniff","Date":"Mon, 21 Mar 2016 13:04:35 GMT","Access-Control-Allow-Origin":"*","Keep-Alive":"timeout=5, max=100","Content-Type":"application\/json; charset=utf-8"},"responseTime":1899,"totalTime":1899}*/

当我使用它工作的RestClient时!

Status:200: OK

1 个答案:

答案 0 :(得分:0)

您是否可以启用wireshark跟踪并比较两种调用方式之间的网络流量,一种来自RestClient,另一种来自HTTP适配器,如果请求格式有任何问题,请查看差异。