RCurl getForm传递http标头 [英] RCurl getForm pass http headers

查看:459
本文介绍了RCurl getForm传递http标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用RCurl的 getForm 函数,这是传递GET参数的唯一好方法,我需要修改一些http头。在getURI中,你只需传递 httpheader = c(Whatever ='whatever',...)就可以了。不幸的是,这个参数似乎被 getForm 忽略。

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.

如何在getForm请求中设置http标头?

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

推荐答案

p>欢迎来到 RCurl 的混乱世界!你发现它的语法没有意义,这不是你的错。

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

getForm 作为第二个参数( ... )。请参阅 usage 部分? getForm

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)

参数部分说:


值对参数。注意,这些不是CURL选项。

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

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

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)




...被解释为控制HTTP请求的CURL选项的命名值。

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

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

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.

因此我的一般建议是总是使用 curlPerform ,而不是任何封装函数(如 getForm getURL ),因为那样你将始终使用一致的语法。

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.

这篇关于RCurl getForm传递http标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆