我对XML很新...
如何将以下XML发送到“https://www.exampleserver.com”?
<?xml version='1.0' encoding='UTF-8'?>
<methodCall>
<methodName>ContactService.add</methodName>
<params>
<param>
<value><string>privateKey</string></value>
</param>
<param>
<value><struct>
<member><name>FirstName</name>
<value><string>John</string></value>
</member>
<member><name>LastName</name>
<value><string>Doe</string></value>
</member>
<member><name>Email</name>
<value><string>there_he_go@itsjohndoe.com</string></value>
</member>
</struct></value>
</param>
</params>
</methodCall>
答案 0 :(得分:4)
使用客户端脚本,不幸的是,您只能将XML发送到与Web服务器所在的域相同的域。这是一项安全功能。但是,您可以将其发送到您自己的服务器并让服务器发送它。
要将其发送到您自己的服务器,您可以执行以下操作:
var xml = '' +
'<?xml version='1.0' encoding='UTF-8'?>' +
'<methodCall>' +
'<methodName>ContactService.add</methodName>' +
'<params>' +
' <param>' +
' <value><string>privateKey</string></value>' +
' </param>' +
' <param>' +
' <value><struct>' +
' <member><name>FirstName</name>' +
' <value><string>John</string></value>' +
' </member>' +
' <member><name>LastName</name>' +
' <value><string>Doe</string></value>' +
' </member>' +
' <member><name>Email</name>' +
' <value><string>there_he_go@itsjohndoe.com</string></value>' +
' </member>' +
' </struct></value>' +
' </param>' +
'</params>' +
'</methodCall>';
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST","https://www.yourdomain.com/thepage",true);
xmlhttp.send(escape(xml));