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.
For example, a web application hosted at http://localhost:8080/Demo/MyExample.html has the origin http://localhost:8080. A server origin contains three parts:
|Scheme||Protocol the web service uses.||http://|
|Host||Domain name or IP address of the service.||localhost|
|Port||TCP port of the web service. If you don't specify a port, the web service uses the default port.||8080|
Once you know the origin of the host web service and the target web service, determine whether requests from the web application to the target web service will be same-origin requests or cross-origin requests. If both origins are identical, requests from the web application to the web service are same-origin requests. If there is any difference between the two origins, requests from the web application to the web service are cross-origin requests.
Browsers running web applications do not impose restrictions on same-origin requests. Web applications that perform cross-origin requests are subject to the Cross-Origin Resource Sharing (CORS) mechanism. By default, a web browser blocks all cross-origin requests made to a target web service that is not configured to support CORS.