移动端JS怎么直接调用webservice接口呢?
testXML () {
let xmlStr =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<params>' +
'<safety>' +
'<clientcode>ImageCenter</clientcode>' +
'<servicecode>CheckInvoice</servicecode>' +
'<time>20171114101333</time>' +
'<ticket>C9A98D036ACCA10EE3E8BEB7FB7474B8</ticket>' +
'</safety>' +
'<serverbody>' +
'<servername>CheckInvoiceImage</servername>' +
'<services>' +
'<service>' +
'<serviceid>1</serviceid>' +
'<checkkey>User_20171114101333</checkkey>' +
'<checktype>4</checktype>' +
'<invoicecode>042001600111</invoicecode>' +
'</service>' +
'</services>' +
'</serverbody>' +
'</params>'
// 创建XMLHttpRequest对象
var xhr = new XMLHttpRequest()
// 打开连接
xhr.open('post', '/CheckInvoice/services/AutoImageCenter.ws', true)
// 设置数据类型
xhr.setRequestHeader('content-type', 'text/xml;charset=utf-8')
// xhr.setRequestHeader('SOAPAction', '111')
xhr.setRequestHeader('SOAPAction', 'http://tempuri.org/')
// 设置回调函数
xhr.onreadystatechange = function () {
// 判断是否发送成功和判断服务端是否响应成功
console.log(xhr, xhr.status, xhr.readyState, xhr.responseText)
if (xhr.readyState === 4 && xhr.status === 200) {
// alert(xhr.responseText)
}
}
// 组织SOAP协议数据
var soapXML = xmlStr
// alert(soapXML)
// 发送数据
xhr.send(soapXML)
}
我这样写会报错
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server.userException</faultcode><faultstring>org.xml.sax.SAXException: Bad envelope tag: params</faultstring><detail><ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">dev-214</ns1:hostname></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
谁做过这种啊,求指导下