如何在 node.js http.request 中发布 XML 数据 [英] how to post XML data in node.js http.request

查看:42
本文介绍了如何在 node.js http.request 中发布 XML 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 http.request 通过 Node.js 向 Web 服务提交 xml 请求.

i am trying to submit a xml request to a web service via Node.js using http.request.

这是我的代码.我的问题是我想将 xml 发布到服务而不是 data=1.

Here is my code. My issue is that instead of data=1 i want to post xml to the service.

http.request({
   host: 'service.x.yyy.x',
   port: 80,
   path: "/a.asmx?data=1",
   method: 'POST'
}, function(resp) {
   console.log(resp.statusCode);
   if(resp.statusCode) {
        resp.on('data', function (chunk) {
            console.log(chunk);
            str +=  chunk;                  
        });
        resp.on('end', function (chunk) {                           
            console.log(str);            
        });                   
  }
}).end();

怎么做?

推荐答案

http.request 返回 ClientRequest 对象,它也是一个可写的流.代替 .end()end(xmlbody).write(xmlbody).end()

http.request returns ClientRequest object which is also a writable stream. Instead of .end() do end(xmlbody) or .write(xmlbody).end()

这篇关于如何在 node.js http.request 中发布 XML 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆