【发布时间】:2016-01-06 01:07:40
【问题描述】:
我正在使用 wso2 的 DAS。我有一个输入适配器类型为 http 的事件接收器。在使用 jquery 的 html 中,我通过 post 方法将 json 发送到此事件。代码很简单:
<script src="jquery.js"></script>
<script>
$( document ).ready(function() {
$("#senddata").click(function(){
$.post("http://localhost:9763/endpoints/ex", '{"event": {"payloadData": {"name": "gggg", "age": 37}}}')
.done(function( data ) {
console.log( data );
});
});
});
</script>
<body>
<input type="button" value="send" id="senddata"></input>
</body>
DAS 在https://localhost:9443 中运行,带有html 和jquery 的应用程序在http://localhost/s 中运行。当我执行应用程序并单击按钮时,控制台显示错误类型“Access-Control-Allow-Origin”。
DAS 文档有一个会话“分析 REST API 的 CORS 设置”(https://docs.wso2.com/display/DAS300/CORS+Settings+for+the+Analytics+REST+API)。我遵循此说明,但没有任何结果。错误仍然存在。
这是我的web.xml配置
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,HEAD,OPTIONS,PUT,DELETE,PATCH</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
另一方面,当我使用 RESTClient 的 firefox 时,结果是正确的。
【问题讨论】:
-
xml配置正确。发送的数据是持久的。但我没有得到服务器的响应。