02-28-2023 08:45 AM - edited 02-28-2023 08:47 AM
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:
My POST-Method VI
My G Web Code looks like that: (With the URL like: http://IP:PORT/WEBSERVICE)
Thank you in advance. I am using LV 2022 Q3 and G Web 2022 Q3.
03-01-2023 03:47 AM
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:
POST:
03-01-2023 04:32 PM
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
03-02-2023 01:11 AM
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?
03-02-2023 09:12 AM
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?
03-03-2023 01:43 AM - edited 03-03-2023 01:46 AM
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?
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?
I hope you are more experienced than me and can see the issue in my Screenshots. Thank you!
03-03-2023 10:13 AM
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.
03-22-2023 02:07 PM
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