我能夠將POSTMAN調用成功: /mfp/api/az/v1/token和/mfpadmin/management-apis/2.0/runtimes/mfp/applicationsMFP 8.0 API在POSTMAN中工作,但不能從AJAX中工作
我正在接收來自/ mfp/api/az/v1 /令牌的不記名令牌,並將其添加到/ mfp/applications的授權標頭中。
我收到來自兩者的200響應,並從每個API獲取預期信息。
那麼,我選擇Ajax代碼從郵差複製了這些工作的API調用:
var getBasic = {
"async": true,
"crossDomain": true,
"url": "https://..../mfp/api/az/v1/token",
"method": "POST",
"headers": {
"authorization": "Basic YXBpYzptZnBhcGlj",
"grant_type": "client_credentials",
"cache-control": "no-cache",
"postman-token": "05a672e5-6141-fd6f-82e2-b282d68dce35",
"content-type": "application/x-www-form-urlencoded"
},
"data": {
"grant_type": "client_credentials",
"scope": "settings.read"
}
}
$.ajax(getBasic).done(function (response) {
console.log(response);
var accessToken = response.access_token;
console.log(accessToken);
var settings = {
"async": true,
"crossDomain": true,
"url": "https://....:8445/mfpadmin/management-apis/2.0/runtimes/mfp/applications",
"method": "GET",
"headers": {
"authorization": "Bearer " + accessToken,
"cache-control": "no-cache"
}
}
console.log(settings);
$.ajax(settings).done(function (response) {
console.log("response: " + response.totalListSize);
});
});
然而,當我在WebUI中運行這個我從/令牌 但我200響應從我的/ mfp /應用程序獲得401(未授權)
爲什麼在郵遞員中工作,但不是從Web UI(Chrome)工作?
我想你應該獲得由代碼訪問令牌,而不是簡單地重新使用現有的令牌。你有沒有嘗試通過代碼獲得它? https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8。0/authentication-and-security/confidential-clients /#獲取訪問令牌 –
我使用getBasic詳細信息獲取不記名令牌。當這個調用完成時,我從響應中獲取access_token並將其傳遞給設置變量(/ mfp/applications)。 –
你是什麼意思的「我然後選擇從郵遞員複製ajax代碼」? –