RCurl getForm pass http headers

*爱你&永不变心* 提交于 2019-12-04 12:35:49

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.

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