CORS Access-Control-Allow-Origin正在进行GET而不是POST

时间:2013-07-15 16:44:49

标签: ajax cors

我尝试使用CORS Filter http://software.dzhuvinov.com/cors-filter-installation.html来解决Access-Control-Allow-Origin的问题。 我按照说明操作,它只能GET而不是POST。我在Tomcat服务器上有Java servlet,我通过我的Web应用程序调用这个servlet,代码在这里:

        var url = "http://server_url:8080/"
            + "gtpapi/testPlan/guid_" + planId + "/packages/" + packId + "/results";
        $.ajax({
            contentType : 'application/json',
            type : "POST",
            crossDomain: true,
            url : url,
            data : JSON.stringify(postData),
            async : false,
            dataType : 'json',
            error : function(XMLHttpRequest) {
                throw XMLHttpRequest.statusText;
            }
        });

这是我的web服务器的web.xml。

<filter>
    <!-- The CORS filter with parameters -->
    <filter-name>CORS</filter-name>
    <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>

    <init-param>
        <param-name>cors.allowOrigin</param-name>
        <param-value>*</param-value>
    </init-param>
     <init-param>
        <param-name>cors.supportedMethods</param-name>
        <param-value>GET, HEAD, POST, OPTIONS</param-value>
   </init-param>
   <init-param>
        <param-name>cors.supportedHeaders</param-name>
        <param-value>Origin, Content-Type, X-Requested-With, Access-Control-Allow-Origin</param-value>
   </init-param>
    <init-param>
        <param-name>cors.supportsCredentials</param-name>
        <param-value>false</param-value>
   </init-param>
</filter>

<filter-mapping>
    <!-- CORS Filter mapping -->
    <filter-name>CORS</filter-name>
    <url-pattern>/gtpapi/*</url-pattern>
</filter-mapping>

我整天尝试了很多方法,但到目前为止没有任何作用。 我还尝试使用“Access-Control-Allow-Origin”,“*”来标题或创建CORSFilter类作为此链接http://padcom13.blogspot.fr/2011/09/cors-filter-for-java-applications.html。但它根本不适合我。有什么想法吗?

0 个答案:

没有答案