开发者

Web server setting Access-Control-Allow-Headers

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜