Enabling CORS for a Web Service
- Updated2023-02-17
- 2 minute(s) read
Enabling CORS for a Web Service
To incorporate resources from a different origin into your web application, configure CORS for the server hosting those resources.
-
Refer to the web service documentation or contact the web service administrator
to verify if the web service allows cross-origin requests using CORS.
Note The target web service must enable cross-origin requests to allow HTTP requests from a WebVI executing in the development environment. Refer to Hosting a Web Application During Development for more information.
-
Determine whether the web service requires credentialed CORS requests.
If the web service requires credentialed requests, refer to Sending a Credentialed Cross-Origin HTTP Request to configure your application to send credentialed requests.
-
Ensure the web service administrator includes an
Access-Control-Allow-Origin header in HTTP responses
to enable cross-origin HTTP requests to the web service.
-
For non-credentialed simple CORS requests, set the Access-Control-Allow-Origin header to one of the following values:
- The wildcard value (*) that allows any origin to access a resource. NI recommends using this value only during the development of your application.
- The origin of the web application performing the HTTP request.
-
For credentialed simple requests, ensure the web service includes the following header values in responses to the web application:
- Access-Control-Allow-Origin header set to the origin of the web application performing the HTTP request.
- Access-Control-Allow-Credentials header set to True.
-
- Responding to a CORS preflight request during a non-simple CORS request
- Handling headers for browser caches
- Accepting additional request headers from a browser
- Allowing the browser to have access to additional response headers
Related Information
- Considerations When Accessing Data from Web Services
If you want to create a web application that sends requests to and receives responses from a web service, you need to know the origin of the web service that hosts the web application as well as the origin of the target web service.
- Configuring CORS for a LabVIEW Web Service
You may need different CORS configurations for each LabVIEW Web Service in your application during development and deployment.
- Sending a Credentialed Cross-Origin HTTP Request
Enable credentials in your WebVI, such as including and storing HTTP cookies, adding HTTP Authorization headers, or permitting TLS client certificates to interact with a web service.