通过nodejs状态代码错误415调用Web服务(SOAP)



我正在尝试通过nodejs调用WCF Web服务(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();

该死...它的愚蠢错误,它应该是标题," 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);
    });
});

相关内容

最新更新