Node.js:使用“原始”格式执行POST请求的最佳方法?

我希望从我的NodeJS服务器执行POST请求。 它需要发送原始的XML数据。

这是什么build议的方法呢?

编辑:添加我目前的沙箱。 还不成功!

var express = require('express'); // call express var app = express(); // define our app using express var bodyParser = require('body-parser'); // configure app to use bodyParser() // this will let us get the data from a POST app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); app.use(bodyParser()); var data = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.__DOMAIN__.com"><soapenv:Header><api:userToken><password>pwd1</password><username>usr_api</username></api:userToken></soapenv:Header><soapenv:Body><api:SearchModels><!--Optional:--><searchText>keyword</searchText></api:SearchModels></soapenv:Body></soapenv:Envelope>'; var options = { host: 'www.__MY_END_POINT_.com', port:443, method: 'POST', headers: { 'Content-Type': 'text/xml', 'Content-Length': data.length } }; var req = http.request(options, function(res) { res.setEncoding('utf8'); res.on('data', function (chunk) { console.log("body: " + chunk); }); }); req.write(data); req.end(); 

谢谢,J.

好的,我错了所需的模块。

错误:var http = require('http');

好方法:var https = require('https');