RCurl getForm 传递 http header

标签 r http curl get rcurl

使用 RCurl 的 getForm 函数,这是传递 GET 参数的唯一好方法,我需要更改一些 http header 。在 getURI 中,您只需传递 httpheader = c(Whatever='whatever',...) 即可。不幸的是,getForm 似乎忽略了该参数。

如何在 getForm 请求中设置 http header ?

最佳答案

欢迎来到 RCurl 的困惑世界!您发现它的语法毫无意义,这不是您的错。

getForm 中,您将标题作为第二个参数(...)传递。看到 用法部分了吗?获取表单:

getForm(uri, ..., .params = character(), .opts = list(), curl = getCurlHandle(),
         .encoding = integer(), binary = NA, .checkParams = TRUE)

arguments 部分说:

... the name-value pairs of parameters. Note that these are not the CURL options.

相比之下,另一个主力函数 getURL 说:

getURL(url, ..., .opts = list(),
        write = basicTextGatherer(.mapUnicode = .mapUnicode),
         curl = getCurlHandle(), async = length(url) > 1,
           .encoding = integer(), .mapUnicode = TRUE)

... named values that are interpreted as CURL options governing the HTTP request.

因此,当使用 getForm 时,您可以将标题作为列表传递,但是当使用 getURL 时,您需要在 httpheader< 中指定它们 参数。

因此,我的一般建议是始终使用 curlPerform 而不是任何包装函数(如 getFormgetURL),因为这样你'将始终使用一致的语法。

关于RCurl getForm 传递 http header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20051258/

相关文章:

ios - 通过http上传视频

php - 仅使用 curl 和 php 获取 http 状态代码

c# - 如何使用 curl 将参数 POST 到 WCF 服务

java - 将 REST\json httpclient4.2 切换为正常的 HttpURLConnection

http - MIME、Internet 媒体类型和 HTTP 之间有什么区别?

php - 不可能的 SSL CAS 证书与 phpCAS 和示例。它只在没有 SSL 服务器验证的情况下工作

r - 如何在 Shiny 中运行计划的跨 session 数据库查询

r - 寻找 dplyr 函数来有条件地应用过滤器

r - 如何拆分数据框,应用某些功能,然后将其重新组合在一起?

r - 如何扩展给定的数字范围以包含由破折号分隔的所有数字