我试图通过节点js调用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();
答案 0 :(得分:0)
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);
});
});