开发者

Web server setting Access-Control-Allow-Headers

开发者 https://www.devze.com 2023-02-28 02:17 出处:网络
I have created a web service in asp.net and trying to access it from an html file from a local machine inside the domain.

I have created a web service in asp.net and trying to access it from an html file from a local machine inside the domain.

I am getting this error

XMLHttpRequest cannot load http://10.112.37.31/amanopoc/Service1.asmx. Request header field SOAPAction is not allowed by Access-Control-Allow-Headers.

try {

if (window.XMLHttpRequest)

  {// code for IE7+, Firefox, Chrome, Opera, Safari

  xmlhttp=new XMLHttpRequest();

  }

else

  {// code for IE6, IE5

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  }

}

catch (e) 

{

    xmlhttp = false; 

}


if( xmlhttp ) 

{



 xmlhttp.open ('POST', postUrl, true);

xmlhttp.onreadystatechange = function() 

{ 





if( xmlhttp.readyState == 4 ) {

 if (xmlhttp.status !=404) 

 {

//alert(xmlhttp.responseText);

//alert("TEST 1");

  var xmlDoc = xmlhttp.responseText;

  if(xmlDoc)

  {

    var x=xmlhttp.responseXML.selectSingleNode("//ObjectToXmlResult").text;

    //var y=x.getElementByTagName("HelloWorldResult");

    alert(x);

  }

  else

  {

    alert("xmlDoc is null");

  }

 }

 else

 {

  alert("xmlht开发者_开发技巧tp.status =" + xmlhttp.status );

 }

} 

};





 xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8'); 

 xmlhttp.setRequestHeader("SOAPAction", soapActionUrl);

 xmlhttp.setRequestHeader("Content-Length", soapHeader.length );  

 xmlhttp.send(soapHeader);

}

can any


on your server set the following header

Access-Control-Allow-Headers : SOAPAction

you may also need

Access-Control-Allow-Origin : *
Access-Control-Allow-Methods : POST,GET,OPTIONS

those last two will need to be tailored to your needs but the above values should get you working.

0

精彩评论

暂无评论...
验证码 换一张
取 消