LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Publish WebService on cRIO using G Web - HTTP-Methods not working / CORS policy Block

Hello everybody, 

 

i am trying to host a Web Server on a cRIO-RT Target (cRIO-9068) using LabVIEW and G Web. I already programmed a sample program that has an LED and a slider that changes the frequency of the LED Flashing. The LED is communicating from Host to WebServer and the Slider the same backwards.

 

So the VI and the WS are communicating via global variables, the WS and the Website via HTTP.

 

I was able to publish the Web Server on the cRIO with the G Web Frontpanel i created that unfortunately is not interactive. In G Web i get the Error:

 

[...] has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. in index.html at line 0

 

I configured a GET and a POST method with an added header to prevent this but it's still not working. Is there a mistake in my method VIs? Does anybody know what could be the issue? I am not that experienced in HTTP.

 

 

My GET-Method VI:

GET.PNG

My POST-Method VI

 

POST.PNG

 

My G Web Code looks like that: (With the URL like: http://IP:PORT/WEBSERVICE)

GWEB.PNG

 

Thank you in advance. I am using LV 2022 Q3 and G Web 2022 Q3.

0 Kudos
Message 1 of 8
(1,606 Views)

I have the feeling it is because of the Post method. When i open the URL of Get and Post method in the browser, while in Debug mode, it opens these sites.

 

GET:

GET.PNG

 

 

POST:

 

POST.PNG

 

 

 

0 Kudos
Message 2 of 8
(1,577 Views)

If you're using NI Web Server instead of application web server then you need to configure CORS in the NI Web Server Config app

~ The wizard formerly known as DerrickB ~
Gradatim Ferociter
0 Kudos
Message 3 of 8
(1,561 Views)

I tried but it seems to only change the Web Server that is hosted on my Laptop. How do i change the policy on a Web Server that is running on a cRIO-Target?

0 Kudos
Message 4 of 8
(1,531 Views)

Well now I feel dumb because you have cRIO in your title, sorry. cRIO does use application web server. Can you look in the browser's development tools and see what headers are being returned?

~ The wizard formerly known as DerrickB ~
Gradatim Ferociter
0 Kudos
Message 5 of 8
(1,498 Views)

No problem! I am really not that experienced in http and Webservers but here are some screenshots i made from the development tools. Is this what you need or do you need anything else?

 

 

header.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

http_err2.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Seems like the G Web application has a problem to convert the JSON. Makes sense because he can't even get data due to the CORS problem. Do you have any suggestions?

 

http_err.PNG

 

I hope you are more experienced than me and can see the issue in my Screenshots. Thank you!

0 Kudos
Message 6 of 8
(1,476 Views)

It's saying the json format isn't valid. In the console of the dev tools shows the error that keeps happening over and over. I'd throw the json being sent into an indicator to see what it looks like and make sure you add some kind of displays to view errors from subVIs while you're testing.

~ The wizard formerly known as DerrickB ~
Gradatim Ferociter
0 Kudos
Message 7 of 8
(1,459 Views)

Hello EBeg,

 

Did you add Confiure CORs to the web VI?  I found I had to add Accept-Language (english)to my headers.  I am using Opera as a web browser.

 

Your GET and POST code looks fine for the web serivices.

 

Did you configure cors.png

0 Kudos
Message 8 of 8
(1,403 Views)