Pregunta

I've tried to execute a XHR request and an iframe approach, but both lead to a dead end. When I use a XHR request I get the (expected) CORS exception, but when I use an iframe I'm not able to send JSON data.

Does somebody know how to do this?

require(["dojo/request/iframe", "dojo/json"], function(iframe, JSON){
    var json = JSON.stringify({"bindingName":"iasistwebservice", "method":"helloWorld", "params": []});
    iframe("http://10.10.51.49:8080/TestProject/restservices/AsistWebService", {
        data: json,
        handleAs: "json",
      }).then(function(data){
        alert ( data );
      });
});

And I've set the appropriate headers(and filters according to https://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#CORS_Filter) on the Tomcat(place where the REST services are running).

¿Fue útil?

Solución

The main problem was that it was a pre flight request(OPTIONS request and after this was verified the POST request would follow).

I've solved the problem by adding the default CORS filter to my Tomcat(Tomcat install directory --> conf --> web.xml):

<filter>
    <filter-name>CorsFilter</filter-name>
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>CorsFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

NOTE: The CORS filter is integrated in V 7.0.41(correct me if I'm wrong) and above.

The request can be done by using the XHR request in Dojo.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top