我订阅了一家财务数据提供商ORATS。软件工程师联系我告知我的GET()请求超时了。他建议在我的GET()请求头中允许gzip编码。该SWE不使用R进行编码,已经提供了一些node.js代码给我参考。
我原本认为httr GET()请求会自动压缩文件到gzip格式。
以下是SWE提供的node.js代码,随后是我的当前R代码,但当我需要从他们的API中拉取更大的文件时,我的R代码便开始超时(无法正常工作)。
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)
我希望将此代码用于请求gzip压缩的文件。 谢谢。
Accept-Encoding
=“gzip”? - IonicSolutions