使用 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
而不是任何包装函数(如 getForm
或 getURL
),因为这样你'将始终使用一致的语法。
关于RCurl getForm 传递 http header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20051258/