LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

WebServices: how to accept http OPTION method request?

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?

0 Kudos
Message 1 of 24
(4,756 Views)

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

0 Kudos
Message 2 of 24
(4,727 Views)

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?

0 Kudos
Message 3 of 24
(4,711 Views)

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.  

0 Kudos
Message 4 of 24
(4,689 Views)

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?

0 Kudos
Message 5 of 24
(4,674 Views)

I am having trouble following this.  Can you put the code up for the VI (a snapshot shoud do)?

 

Matt

0 Kudos
Message 6 of 24
(4,670 Views)

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

 

0 Kudos
Message 7 of 24
(4,658 Views)
If the web service doesn't respond properly to an OPTIONS method, you're stuck. If it is that important a feature you will need to run a real web server.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 8 of 24
(4,646 Views)

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?

0 Kudos
Message 9 of 24
(4,628 Views)
That's correct. You have to drop the web service and use a real web server.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 10 of 24
(4,624 Views)