我订阅了一个金融数据提供商ORATS。软件工程师联系我,让我知道我的GET()请求正在超时。他说在GET()请求头中允许gzip编码。SWE没有在R中进行编码,并向我发送了一些node.js代码以供依赖。
我认为httr ()请求会自动将文件压缩为gzip。
下面是SWE提供的node.js代码,然后是我当前的R代码,直到我增加了从他们的API中提取的文件的大小(开始超时)。
const request = require('request');
const options = {
url: 'https://api.orats.io/data/cores/general?include=earn',
headers: {
'Authorization' : 'your authorization token',
'Accept-Encoding' : 'gzip'
},
gzip : true
};
request(options, function(err, response, body){
// Body is already uncompressed b/c the request library uncompresses it for you.
console.log(JSON.parse(body));
});
R code:
library(httr)
x = GET(url, add_headers(Authorization = token))
y = rawToChar(x$content)我希望这段代码请求gziped文件。谢谢。
发布于 2019-05-13 05:51:37
还向httr请求添加相同的Accept-Encoding行:
library(httr)
x = GET(url, add_headers(.headers = c('Authorization'= token,
'Accept-Encoding' = 'gzip, deflate')))https://stackoverflow.com/questions/55977993
复制相似问题