gpt4 book ai didi

r - 使用 httr R 接受 gzip 编码

转载 作者:搜寻专家 更新时间:2023-10-31 23:56:34 24 4
gpt4 key购买 nike

我订阅了金融数据提供商 ORATS。软件工程师联系我,让我知道我的 GET() 请求超时。他说允许在我的 GET() 请求 header 中使用 gzip 编码。 SWE 不使用 R 编写代码,而是向我发送了一些 node.js 代码以供引用。

我认为 httr GET() 请求会自动将文件压缩为 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)

我希望此代码请求 gzip 文件。谢谢。

最佳答案

也将相同的 Accept-Encoding 行添加到 httr GET 请求中:

library(httr)
x = GET(url, add_headers(.headers = c('Authorization'= token,
'Accept-Encoding' = 'gzip, deflate')))

请注意 httr automatically decompresses the response .

关于r - 使用 httr R 接受 gzip 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55977993/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com