流星:尝试向SOAP API发送请求时出现Access-Control-Allow-Origin问题

时间:2018-07-24 01:32:39

标签: javascript meteor request cors xmlhttprequest

在流星客户端,我需要向SOAP API发送请求。如您所见,发送请求的函数:

const xmlHttp = new XMLHttpRequest();
  xmlHttp.open(
    'POST',
    'http://www.holidaywebservice.com//HolidayService_v2/HolidayService2.asmx?wsdl',
    true
  );
  const sr = `<?xml version="1.0" encoding="utf-8"?> 
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hs="http://www.holidaywebservice.com/HolidayService_v2/">
        <soapenv:Body>
           <hs:GetHolidaysAvailable>
           <hs:countryCode>UnitedStates</hs:countryCode>
           </hs:GetHolidaysAvailable>
         </soapenv:Body>
      </soapenv:Envelope>`;

  xmlHttp.onreadystatechange = () => {
    if (xmlHttp.readyState === 4) {
     if (xmlHttp.status === 200) {
       //...
     }
    }
  };
  xmlHttp.setRequestHeader(
    'Access-Control-Allow-Headers',
    'X-Requested-With, Content-Type, Authorization'
  );
  xmlHttp.setRequestHeader(
    'Access-Control-Allow-Methods',
    'GET,PUT,POST,DELETE,OPTIONS'
  );
  xmlHttp.setRequestHeader('Access-Control-Allow-Origin', '*');
  xmlHttp.send(sr);
}

在chrome控制台上,我得到:Access-Control-Allow-Origin

我阅读了类似的问题,但发现的解决方案不起作用。

我该如何解决?

0 个答案:

没有答案
相关问题