【问题标题】:Difference between response of GET function and getURIGET函数响应和getURI的区别
【发布时间】:2019-01-12 19:43:53
【问题描述】:

所以我想向一个 API 发出多个请求以加快结果速度,因为串行速度太慢了。因此,我尝试使用 GetURI,但是,API 不返回任何值,而 GET 请求则返回!

所以我尝试了各种解决方案,例如 GETURI、GETURL 和 getURIAsynchronous,但是,它们都没有返回值。我想这是因为 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 应该返回 GET 请求的值,但它没有

【问题讨论】:

    标签: r rcurl


    【解决方案1】:

    查看了 SitePrice API。似乎API使用https而不是使用http。您将获得 getURL 作为 Object Moved 的初始结果...

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

    这里有两个解决方案:

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

      res <- getURIAsynchronous(APIcall, .opts=curlOptions(followlocation=TRUE))
      
    2. 使用 https 和 getURIAsynchronous 函数

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      • 1970-01-01
      • 1970-01-01
      • 2017-09-04
      • 1970-01-01
      • 2017-09-24
      • 2011-02-20
      相关资源
      最近更新 更多