-1



At first let me explain I am IT student and I have a problem with CORS.
I have to call a remote service, which is on another domain, I got specified header and data structure (see bellow). I have implemented XMLHttpRequest (see bellow), but there is an error which cannot be fixed (after few days of googling): No 'Access-Control-Allow-Origin' header is present on the requested resource..
Is this server-side problem, or do I have a mistake in my headers?
Thanks in advance!

Header definiton:
"header":
{"actionType" : "weather",
"alphabet": "latin",
"version": "9.43.2",
"unicodeHidden": "true"}

My code:

var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://remote-site.net/service', true);
xhr.setRequestHeader('actionType', 'weather');
xhr.setRequestHeader('alphabet', 'latin');
xhr.setRequestHeader('version', '9.43.2');
xhr.setRequestHeader('unicodeHidden', "true");
xhr.onload = function () {
  alert("OK");
 };
 xhr.onerror = function () {
    alert("error");
  };
 xhr.send(dataToSend);
ZPA
  • 97
  • 2
  • 11

2 Answers2

0

The problem you are encountering is because the remote servers CORS policy is not allowing cross domain requests.

The remote server must send a Access-Control-Allow-Origin: * or other Access-Control-Allow-Origin header to allow remote requests.

If you are unable to change code for the other domain, the only way to get around this is to proxy the request. This means you have to create a simple PHP script that will act as a middle man between your WebApp and the remote server.

Thakkie
  • 604
  • 4
  • 17
  • So that should be server-side problem? I do not own the remote server. – ZPA Apr 24 '17 at 16:31
  • 1
    Year server side. I made an edit to point you in the right direction If you really HAVE to get around CORS.. – Thakkie Apr 24 '17 at 16:37
-1

I have installed POSTMAN plugin for Chrome and solved my problem.

ZPA
  • 97
  • 2
  • 11