[英]How to use an API with an app Fiori (SAPUI5)
I am trying to use this Mercedes Benz API in my app. 我正在尝试在我的应用程序中使用此Mercedes Benz API 。 Inside controller I have a ajax request:
在控制器内部,我有一个ajax请求:
onInit : function () {
var oModel = new JSONModel();
var url = 'https://api.mercedes-benz.com/image/v1/vehicles/WDDZH3HB8JA394212/components?apikey=my_apikey';
$.ajax({
beforeSend: function() {
//armamos la url y la asignamos a una var
},
url: url,
type: 'GET',
accepts: "application/json",
success: function (resp) {
console.log(resp)
},
error: function (jqXHR, estado, error) {
console.log(error +":" + " " + estado)
},
timeout: 10000
});
},
I just want response as OK
but getting some error: 我只希望响应
OK
但出现一些错误:
Request header field X-XHR-Logon is not allowed by Access-Control-Allow-Headers in preflight response.
飞行前响应中的Access-Control-Allow-Headers不允许请求标头字段X-XHR-Logon。
If you take a look to the documentation API I just need the API key. 如果您看一下文档API,我只需要API密钥。 Maybe I am doing something wrong?
也许我做错了什么? Guide me if you has use an API inside a FIORI app it will be thankful
指导我,如果您在FIORI应用程序中使用过API,将不胜感激
NOTE: my fiori server is on premise so we don't use SCP 注意:我的Fiori服务器位于内部,因此我们不使用SCP
If you really want to do an XHR you need to whitelist APIKEY in neo-app.json like this 如果您真的想执行XHR,则需要在neo-app.json中将APIKEY列入白名单
{
"welcomeFile": "/webapp/index.html",
"routes": [{
...
],
"sendWelcomeFileRedirect": true,
"headerWhiteList": [
"APIKey"
]
}
Otherwise I strictly recommend using destinations, explained in here: 否则,我强烈建议您使用目的地,如此处所述:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.