使用node.js中的XML数据发送POST请求:错误400;客户端发送的请求在语法上不正确”;

使用node.js中的XML数据发送POST请求:错误400;客户端发送的请求在语法上不正确”;,node.js,xml,post,request,node-https,Node.js,Xml,Post,Request,Node Https,我试图用node.js重现Python POST请求(已验证工作)。 这是一个相当简单的POST请求发送和接收XML数据的过程 但是,我得到了客户机发送的请求在语法上不正确错误,尽管我的XML是有效的(经过验证的),并且直接取自Python示例。我做错了什么 我的代码(可复制): //文档: // https://wiki.solargis.com/display/public/WS+API+技术+文档#WSAPItechnicaldocumentation DatadeliveryWebser

我试图用node.js重现Python POST请求(已验证工作)。 这是一个相当简单的POST请求发送和接收XML数据的过程

但是,我得到了
客户机发送的请求在语法上不正确
错误,尽管我的XML是有效的(经过验证的),并且直接取自Python示例。我做错了什么

我的代码(可复制):

//文档:
// https://wiki.solargis.com/display/public/WS+API+技术+文档#WSAPItechnicaldocumentation DatadeliveryWebservice(APIforningTimeSeriesData)
// https://nodejs.org/api/http.html#http_http_request_options_callback
// https://nodejs.org/api/http.html#http_request_write_chunk_encoding_callback
// https://nodejs.org/api/https.html
让https=require('https');
常量api_键='demo';
var请求=“”+
'' +
'' +
'' +
'';
var request_utf8=缓冲区。from(请求“utf-8”);
让选项={
主持人:“solargis.info”,
路径:`/ws/rest/pvplanner/calculate?key=${api_key}`,
标题:{
“内容类型”:“应用程序/xml”,
//“内容长度”:缓冲区.ByTeleLength(请求),
//'传输编码':'分块',//请参阅https://nodejs.org/api/http.html#http_request_write_chunk_encoding_callback
},
方法:“POST”,
};
const req=https.request(选项,(res)=>{
log(`STATUS:${res.statusCode}`);
log(`HEADERS:${JSON.stringify(res.HEADERS)}`);
res.setEncoding('utf8');
res.on('数据',(块)=>{
log(`BODY:${chunk}`);
});
res.on('结束',()=>{
log('响应中没有更多数据');
});
});
请求开启('错误',(e)=>{
错误(`problemwithrequest:${e.message}`);
});
//将数据写入请求主体
请求写入(请求utf8);
请求结束();
输出:

STATUS: 400
HEADERS: {"date":"Wed, 29 Jul 2020 10:00:07 GMT","server":"Apache","set-cookie":["JSESSIONID=4F3F9848F6E115329F6E00624341EB2E.balanced_ws1; Path=/ws/; Secure; HttpOnly"],"content-length":"968","connection":"close","content-type":"text/html;charset=utf-8","x-pad":"avoid browser bug"}
BODY: <html><head><title>Apache Tomcat/7.0.41 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 400 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The request sent by the client was syntactically incorrect.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.41</h3></body></html>
No more data in response.
状态:400
标题:{“日期”:“Wed,Jul 29 2020 10:00:07 GMT”,“服务器”:“Apache”,“设置cookie”:[“JSESSIONID=4f3f9848f6e115329f6e0624341eb2e.balancedws1;Path=/ws/;Secure;HttpOnly”],“内容长度”:“968”,“连接”:“关闭”,“内容类型”:“text/html;charset=utf-8”,“x-pad”:“避免浏览器错误”}
正文:Apache Tomcat/7.0.41-错误报告HTTP Status 400-
类型状态报告

消息描述客户端发送的请求在语法上不正确。


Apache Tomcat/7.0.41 没有更多的数据响应。
找到了问题。我从错误的示例将请求发布到URL! 正确的
路径
行是
路径:`/ws/rest/datadelivery/request?key=${api\u key}`,