GET函数响应和getURI的区别

Difference between response of GET function and getURI

所以我想向 API 发出多个请求以加快结果的速度,因为在串行中它太慢了。因此,我正在尝试使用 GetURI,但是,API 没有 return 任何值,而 GET 请求有!

所以我尝试了各种解决方案,如 GETURI、GETURL 和 getURIAsynchronous,但是,none 其中 return 是一个值。我想这是因为 API 需要很长时间来处理查询。我将包含我的测试密钥,但是,假设这不会被滥用

links<- c("zalando.nl", "bol.com")
key <- "SILB-DBCA-4523"
APIcall <- paste0("http://www.siteprice.org/WorthApi.aspx?type=1&key=", key, "&url=", links)

#With GET, so serial
res <-GET(APIcall[1])
res1 <- rawToChar(res$content)
as.integer(unlist(xmlToList(xmlParse(res1)))[2])

#With GetURI
res <- getURIAsynchronous(APIcall)
res1 <- rawToChar(res$content)
as.integer(unlist(xmlToList(xmlParse(res1)))

getURIAsynchronous 应该return GET 请求的值,但它不会

查看网站价格 API。似乎 API 使用的是 https 而不是 http。当对象移动时,您将获得 getURL 的初始结果...

GET 函数只会转到您的重定向页面,即 https 页面,但 RCurl 包中的 getURI 默认是获取原始页面。

这里有两个解决方案:

  1. 使用 followlocation=TRUE 选项将 http 重定向到 https

    res <- getURIAsynchronous(APIcall, .opts=curlOptions(followlocation=TRUE))
    
  2. 使用带 getURIAsynchronous 功能的 https

    APIcall <- paste0("https://www.siteprice.org/WorthApi.aspx?type=1&key=", key, "&url=", links)