Javascript 读取REST POST响应节点.js
我能够在rest客户端中测试post调用,该调用显示如下标题:Javascript 读取REST POST响应节点.js,javascript,node.js,rest,https,http-post,Javascript,Node.js,Rest,Https,Http Post,我能够在rest客户端中测试post调用,该调用显示如下标题: Cache-Control: no-cache, no-store, must-revalidate Connection: keep-alive Content-Encoding: gzip Content-Language: en Content-Length: 49 Content-Type: application/json Date: Fri, 14 Apr 2017 21:05:42 GMT 我调用post的代码如下所
Cache-Control: no-cache, no-store, must-revalidate
Connection: keep-alive
Content-Encoding: gzip
Content-Language: en
Content-Length: 49
Content-Type: application/json
Date: Fri, 14 Apr 2017 21:05:42 GMT
我调用post的代码如下所示:
var https = require('https');
... var jsonObject = JSON.stringify({
"Name" : optyName
});
// prepare the header
var postheaders = {
'Content-Type' : 'application/vnd.oracle.adf.resourceitem+json',
'authorization' : 'Basic am9obi5kdW5iYXI6dnBoODk1ODM=',
gzip: true
};
// the post options
var optionspost = {
host : 'myhost',
port : 443,
path : '/salesApi/resources/11.1.11/opportunities?fields=OptyId&onlyData=true',
method : 'POST',
headers : postheaders,
};
// do the POST call
var reqPost = https.request(optionspost, function(error,response,body) {
console.log('the decoded data is: ' + body)
});
reqPost.write(jsonObject);
reqPost.end();
}
但我得到的是印刷品:
the decoded data is: undefined
var http=require(“http”),
zlib=要求(“zlib”)
函数getgzip(url,回调){
//用于存储流式解压缩的缓冲区
var缓冲区=[]
http.get(url, function(res) {
// pipe the response into the gunzip to decompress
var gunzip = zlib.createGunzip();
res.pipe(gunzip);
gunzip.on('data', function(data) {
// decompression chunk ready, add it to the buffer
buffer.push(data.toString())
}).on("end", function() {
// response and decompression complete, join the buffer and return
callback(null, buffer.join(""));
}).on("error", function(e) {
callback(e);
})
}).on('error', function(e) {
callback(e)
});
}
getgzip(url、函数(错误、数据){
控制台日志(数据);
}); var http=require(“http”),
zlib=要求(“zlib”)
函数getgzip(url,回调){
//用于存储流式解压缩的缓冲区
var缓冲区=[]
http.get(url, function(res) {
// pipe the response into the gunzip to decompress
var gunzip = zlib.createGunzip();
res.pipe(gunzip);
gunzip.on('data', function(data) {
// decompression chunk ready, add it to the buffer
buffer.push(data.toString())
}).on("end", function() {
// response and decompression complete, join the buffer and return
callback(null, buffer.join(""));
}).on("error", function(e) {
callback(e);
})
}).on('error', function(e) {
callback(e)
});
}
getgzip(url、函数(错误、数据){
控制台日志(数据);
}); 您正在代码中打印响应正文,而不是响应标题 请尝试以下代码以查看标题:
var reqPost = https.request(optionspost, function(error,response,body) {
console.log('response headers: ' + response.getHeaders())
});
您正在代码中打印响应正文,而不是响应标题 请尝试以下代码以查看标题:
var reqPost = https.request(optionspost, function(error,response,body) {
console.log('response headers: ' + response.getHeaders())
});