RCurl getForm pass http headers

点点圈 提交于 2019-12-21 20:46:08

问题


Using RCurl's getForm function, which is the only nice way of passing in GET-parameters, I need to alter some http headers. In getURI, you just pass httpheader = c(Whatever='whatever',...) and it'll work. Unfortunately, that argument seems to be ignored by getForm.

How do I set the http headers in a getForm request?


回答1:


Welcome to the confusing world of RCurl! You've discovered that its syntax makes no sense, which is not your fault.

In getForm you pass headers as the second argument (the ...). See the usage section of ? getForm:

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

The arguments section says:

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

By contrast, the other workhorse function getURL says:

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.

Thus, when using getForm, you can just pass the headers as a list, but when using getURL, you need to specify them in a httpheader argument.

My general advice is therefore to always use curlPerform instead of any of the wrapper functions (like getForm or getURL), because then you'll always be using a consistent syntax.



来源:https://stackoverflow.com/questions/20051258/rcurl-getform-pass-http-headers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!