【发布时间】:2017-05-12 04:22:23
【问题描述】:
我是 apiman 的新手,我正在尝试将一些 API 调用与 Jquery 一起使用。但不幸的是我得到了这个错误:
XMLHttpRequest 无法加载 https://apigtw.url/apiman-gateway///1.0/?apikey=9999999-8888-6666-33333-968a712ce68b。 请求中不存在“Access-Control-Allow-Origin”标头 资源。因此,Origin 'http://myapp.local' 不允许访问。 响应的 HTTP 状态代码为 500。
所以,我正在使用一些策略,例如:
Keycloak 授权政策:
Require OAuth: true
Require Transport Security: true
Blacklist Unsafe Tokens: false
Realm: https://sso.local/auth/realms/test-realm
Keycloak Realm Certificate: <keycloak key certificate>
Forward Realm Roles? true
授权策略配置:
Path: .*
Verb: *
Required Role: my-role
我错过了关于 apiman 配置的内容吗?
我觉得应该加CORs,但是不知道有没有必要。我尝试使用它,但仍然出现错误。
请帮忙
有人知道如何配置 APIMan CORs 吗?
编辑:
这似乎已在issue 516 中解决,但我仍然会发生。我正在使用 APIMan 1.2.3 版
这是响应标头:
Connection:close
Content-Type:application/json
Date:Wed, 28 Dec 2016 13:54:08 GMT
Server:Apache/2.4.18 (Ubuntu)
Transfer-Encoding:chunked
X-Gateway-Error:API not public.
X-Powered-By:Undertow/1
和
这是请求标头:
Accept:*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4
Access-Control-Request-Headers:authorization, x-api-key
Access-Control-Request-Method:GET
Connection:keep-alive
Host: apiman.url
Origin:http://192.168.56.22:8080
Referer:http://192.168.56.22:8080/app
User-Agent:Mozilla/5.0 ...
Query String Parameters
view source
view URL encoded
这是我的 ajax 请求:
$.ajax({
url: 'https://apiman.url/apiman-gateway/<org>/<api>/1.0/<method>?apikey=xxxxxx-xxxxx-xxxxx-xxxxx',
headers: {
'Content-Type':'application/json',
'Accept' : 'application/json',
'Authorization' : 'Bearer ' + keycloak.token
},
method: 'GET',
dataType: 'json',
success: function(data){
console.log('header1', data);
}
});
【问题讨论】:
-
谢谢!该链接具有类似的内容,可以帮助我。但我相信我可以通过此链接 'CORS? Of Course!' 添加更多信息。
-
也许这个问题太笼统了。我会改变这个
标签: jquery ajax cors keycloak apiman