【问题标题】:Invoking Web Service(Soap) through nodejs Status Code error 415通过nodejs状态码错误415调用Web服务(Soap)
【发布时间】:2014-02-04 16:56:51
【问题描述】:

我正在尝试通过 nodejs 调用 WCF WebService(SOAP 请求)。我收到 415(不支持的媒体类型)http 状态错误代码。知道我缺少什么吗?

var http = require('http');

var options = {    
  host:'localhost',
  port:'34563',
  path:'/Service1.svc',
  connection:'keep-alive',
  accept:'*/*',
  method:'POST',
  header: {
      'Content-Type':'text/xml;charset="UTF-8"',
      'Content-Length':data.length,
      'Accept':'*/*',
      'SOAPAction':'http://tempuri.org/IService1/GetData'
  }
};

var req=http.request(options, function(res) {
    console.log(res.statusCode);
    res.on('data', function(data) {
        console.log(data);
    });
    res.on('end', function() {

    });
    res.on('error', function(error) {
        console.log('1'+error);
    });
});

var data='<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">'+
  '<s:Body>'+
    '<GetData xmlns="http://tempuri.org/">'+
      '<value>12</value>'+
    '</GetData>'+
'</s:Body>' +
    '</s:Envelope>';


req.write(data);
req.end();

【问题讨论】:

    标签: node.js wcf soap


    【解决方案1】:

    该死的......这是愚蠢的错误, 它应该是标题,'s'错过了。

    var options = {    
      host:'localhost',
      port:'34563',
      path:'/Service1.svc',
      connection:'keep-alive',
      accept:'*/*',
      method:'POST',
      headers: {
          'Content-Type':'text/xml;charset="UTF-8"',
          'Content-Length':data.length,
          'Accept':'*/*',
          'SOAPAction':'http://tempuri.org/IService1/GetData'
      }
    };
    
    
    var req=http.request(options, function(res) {
        console.log(res.statusCode);
        var body = '';
        res.on('data', function(data) {
            body += data;
        });
        res.on('end', function() {
            console.log(body);
        });
        res.on('error', function(error) {
            console.log(error);
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-09
      • 1970-01-01
      • 1970-01-01
      • 2017-06-08
      • 1970-01-01
      • 2010-09-22
      • 1970-01-01
      相关资源
      最近更新 更多