如何解决XMLHttpRequest在NodeJs中返回状态为0的响应“未定义”
我正在向EJBCA Web服务发送请求。请在下面查看我的代码。我收到undefined
作为回应,正在打印的状态为0。
let XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;
const fs = require('fs');
let xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST','https://104.211.18.242/ejbca/ejbcaws/ejbcaws',true,'ejbcaadmin','iBOTControls@123');
var strRequest = `
<x:Envelope
xmlns:x="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ws="http://ws.protocol.core.ejbca.org/">
<x:Header/>
<x:Body>
<ws:getAvailableCAs></ws:getAvailableCAs>
</x:Body>
</x:Envelope>
`;
xmlhttp.setRequestHeader('Content-Type','text/xml; charset=utf-8');
xmlhttp.setRequestHeader('Access-Control-Allow-Origin','*');
xmlhttp.setRequestHeader('Access-Control-Allow-Methods','GET,POST,PATCH,PUT,DELETE,OPTIONS');
xmlhttp.setRequestHeader('Access-Control-Allow-Headers','Origin,X-Requested-With,Content-Type,Accept,x-client-key,x-client-token,x-client-secret,Authorization');
//send the SOAP request
xmlhttp.send(strRequest);
//Callback function for response
xmlhttp.onreadystatechange = function () {
console.log(xmlhttp.response) // returns undefined
console.log(xmlhttp.status) // prints 0
fs.writeFileSync('./response.txt',xmlhttp.responseXML)
}
向此Web服务发送请求需要https客户端身份验证。通过浏览器发送请求时,我必须选择一个证书,然后收到200条响应。由于我没有将证书附加在node.js中,因此会失败吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。