大家好我必须与外部服务器建立连接才能通过XMLHTTPRequest请求数据。 我已经创建了一个页面,但是当我发送请求时,请回复此错误:
错误! 解析器:请求XML(oracle.xml.parser.v2.XMLParseException:Start 预期的根元素。错误号:4001)
我不知道是否是解析或字符或其他问题。 这是我的脚本代码:
<script type="text/javascript">
var req = null ;
var firsttime = false;
function sendRequest(){
var urlStr="http://mylink.it";
var xmlString="";
xmlString="<?xml version='1.0' encoding='UTF-8'?><BOOKING type='COR' lang='it-IT' returnURLNeed='no' returnURL='http://' AGENTCODE='XXXX' AGENTPASSWORD='YYYY' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='http://link/schema/CountryRequestV6Snd.xsd'><DATA ALL_COUNTRIES='YES'/></BOOKING>";
createHTTPRequestObject();
var resp = getResponseText(urlStr+"?"+xmlString,null);
}
function createHTTPRequestObject(){
req=null ;
var pXmlreq = false ;
if (window.XMLHttpRequest) {
pXmlreq = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
try{
pXmlreq = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e1) {
try{
pXmlreq = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e2) {
}
}
}
req = pXmlreq ;
}
function getResponseText(action,query,method,async,contenttype){
if(method==null){
method="POST";
}
if(async==null){
async="true";
}
if(contenttype==null){
contenttype = "application/x-www-form-urlencoded";
}
console.log("open");
req.onreadystatechange= function() {
if (req.readyState == 1) {
if (firsttime==false){
firsttime = true;
req.setRequestHeader("Content-Type", contenttype);
if(query){
console.log("send request");
req.send(query);
}else{
console.log("send request2");
req.send();
}
}
}
if (req.readyState >= 4) {
var serverResponse = req.responseText;
console.log(serverResponse);
}
}
req.open(method,action, async);
}
</script>
我的帖子请求 POST
/trlink/link1/trlink?<?xml%20version='1.0'%20encoding='UTF-8'?><BOOKING%20type='COR'%20lang='it-IT'%20returnURLNeed='no'%20returnURL='http://'%20AGENTCODE='XXX'%20AGENTPASSWORD='YYY'%20xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'%20xsi:noNamespaceSchemaLocation='http://link/CountryRequestV6Snd.xsd'><DATA%20ALL_COUNTRIES='YES'/></BOOKING> HTTP/1.1