06-22-2015 06:47 AM
We are implementing few WebServices and we have to implement WS that respect CORS mechanism described: http://www.html5rocks.com/en/tutorials/cors/#toc-adding-cors-support-to-the-server
The main problem is that we cannot create VI that accept "OPTIONS" http method.
So what we have to do right now? Any solution?
06-22-2015 05:09 PM
To add CORS support, you will need to provide an appropriate header. Using the Web Request::Set HTTP Header method, set the header "Access-Control-Allow-Origin" to the wildcard value of "*" (or you can specify origin explicitly, but this is sufficient).
Cheers, Matt
06-23-2015 01:30 AM
Hi Matt!
Your method is ok for POST Method request with content type "text/plain".
If you need to implement PUT Method with content type "application/json" you have to handle preflight requests with OPTIONS Method.
so what we have to do?
06-23-2015 09:49 AM
Set the header 'Content-Type' to 'application/json' if you are pushing data from the server. But, I use a Post method for pushing an XML stream onto my server and I do not have to do this. Under HTTP Method VI Settings I simply set the Output Type to Terminal (since I pass the data through a terminal) and set the Output format to XML (but you can set it to JSON also). If you are streaming data, you will have to set the Output Type under Web Service Properties-> HTTP Method VI Settings to Stream and check the boxes Use headers and Buffered.
06-24-2015 01:40 AM
Hi Matt thanks for your answer.
The main problem is not related to the Output Type configuration, we already have many WS with Stream Output and so on.
The problem is on the first configuration tab, the one named "URL Mapping". As you can see there are no "OPTIONS" method to select so if the browser tries to make the preflight call as CORS mechanism indicates the result is just a "404 Not Found" error.
So...shortly how LabView could accept OPTIONS Method request from browser?
06-24-2015 01:42 AM
I am having trouble following this. Can you put the code up for the VI (a snapshot shoud do)?
Matt
06-24-2015 02:21 AM
There is nothing special on VI side.
1) Just create a simple VI with "PUT" method and Output as you want.
2) create on different domain a simple html with one button and onclick javascript action and do something like:
$.ajax({
url: 'http://addressLabViewWebServices/PUTTest',
type: 'PUT',
data: { data: "data" },
success: function () { alert('PUT completed'); },
error: function () { alert('PUT error'); },
});
3) Click on the button and see on the "network" debug section of the browser the error: Method OPTIONS 404 error.
Documentation: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
Just read the Prefligth section.
So now the question still the same....how to accept OPTIONS Method request with LabView WebServices?
Thanks.
Diego
06-24-2015 04:21 AM
06-24-2015 09:25 AM
I think that this is not a real solution, i mean...there is no way to embed VI WebServices into a different web server.
am i right?
06-24-2015 09:29 AM