xml - Node.js:使用 "raw"格式执行 POST 请求的最佳方式?

标签 xml node.js post

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

建议采用什么方法?

编辑:添加我当前的沙箱。尚未成功!

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');

关于xml - Node.js:使用 "raw"格式执行 POST 请求的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26467075/

相关文章:

api - GDAX Post Call 返回无效签名

java - 使用 StAX API 编写 html

node.js - 将范围传递给 db.collection.group

java - 在 Java 中将具有无效 XML 字符的任意 JSON 转换为 XML

node.js - Node js将请求绑定(bind)到不同的接口(interface)或IP地址

node.js - 如何从 socket-io-redis 获取 redis 存储客户端?

java - html 到 jsp 电子邮件表单 post - 空参数

ios - 如何使用新的 Apple Swift 语言发布 JSON

javascript - DOM4 中已弃用 CDATA 节节点

javascript - 获取具有最大值的节点的id