gpt4 book ai didi

RCurl - bool 选项

转载 作者:行者123 更新时间:2023-12-01 22:58:18 27 4
gpt4 key购买 nike

这些 Curl 文档:http://curl.haxx.se/docs/manpage.html#-d列出许多 bool 选项。

如何在 RCurl 的 postForm 调用中指定这些选项?例如,如何指定 --sslv3 标志?

我试过了

postForm(url, .opts = list(sslv3=TRUE))

但收到错误:

Warning message:
In mapCurlOptNames(names(.els), asNames = TRUE) :
Unrecognized CURL options: sslv3

提前致谢。

解决方案

通过一些尝试和错误,我发现这是可行的:

options(RCurlOptions = list(sslversion=3))
postForm(url)

如果有人能澄清如何将 Curl 选项转换为 RCurl 选项,我们将不胜感激!

最佳答案

Curl 代表一些东西 http://daniel.haxx.se/docs/curl-vs-libcurl.html 。这里的问题是您正在查看curl命令行工具的功能,而不是想询问libcurl库如何实现某些功能。

RCurl 使用 libcurl 库。这可以通过 api 访问。此处列出了 api 中使用的“符号”http://curl.haxx.se/libcurl/c/symbols-in-versions.html 。我们可以将它们与 RCurl 列出的选项进行比较:

library(RCurl)

cInfo <- getURL("http://curl.haxx.se/libcurl/c/symbols-in-versions.html")
cInfo <- unlist(strsplit(cInfo, "\n"))
cInfo <- cInfo[grep("CURLOPT_", cInfo)]
cInfo <- gsub("([^[\\s]]*)\\s.*", "\\1", cInfo)
cInfo <- gsub("CURLOPT_", "", cInfo)
cInfo <- tolower(gsub("_", ".", cInfo))

listCurlOptions()[!listCurlOptions()%in%cInfo]

从上面我们可以看到,所有 RCurl 选项都源自 libcurl api 符号。这 CURLOPT_已删除_替换为 .并且字母被降级为小写。

接下来的问题是这些符号代表什么类型。我通常只看php 库文档来发现这一点。 http://php.net/manual/en/function.curl-setopt.php列表

CURLOPT_SSLVERSION The SSL version (2 or 3) to use. By default PHP will try to determine this itself, although in some cases this must be set manually.

作为整数类型。期望值 2 或 3。

或者您可以查看 curl_easy_setopt手册页http://curl.haxx.se/libcurl/c/curl_easy_setopt.html .

CURLOPT_SSLVERSION

传递一个 long 参数来控制尝试使用的 SSL/TLS 版本。可用的选项有:

CURL_SSLVERSION_DEFAULT

默认操作。这将尝试找出远程 SSL 协议(protocol)版本,即 SSLv3 或 TLSv1(但不包括 SSLv2,它在 7.18.1 中默认被禁用)。

CURL_SSLVERSION_TLSv1

强制 TLSv1

CURL_SSLVERSION_SSLv2

强制 SSLv2

CURL_SSLVERSION_SSLv3

强制 SSLv3

它说我们需要传递一个长整型值 CURL_SSLVERSION_SSLv3规定sslv3。CURL_SSLVERSION_SSLv3的值是多少?我们可以检查RCurl:::SSLVERSION_SSLv3

> c(RCurl:::SSLVERSION_DEFAULT, RCurl:::SSLVERSION_TLSv1, RCurl:::SSLVERSION_SSLv2, RCurl:::SSLVERSION_SSLv3)
[1] 0 1 2 3
>

因此实际上 sslversion 的允许值为 0、1、2 或 3。

因此,这种情况下的困惑是由curl程序引起的,该程序可能使用libcurl api以二进制方式实现这一点。

因此在这种情况下使用此选项的正确方法是:

postForm(url, .opts = list(sslversion = 3))

or

postForm(url, .opts = list(sslv = 3))

您可以使用较短的 sslv.opts被传递到mapCurlOptNames这将使用 pmatch查找sslversion .

为了公平起见 RCurl 的作者http://www.omegahat.org/RCurl/philosophy.html 中对此进行了全部解释也位于/RCurl/inst/doc/philosophy.html .摘录如下:

Each of these and what it controls is described in the libcurl man(ual) page for curl_easy_setopt and that is the authoritative documentation. Anything we provide here is merely repetition or additional explanation.

The names of the options require a slight explanation. These correspond to symbolic names in the C code of libcurl. For example, the option url in R corresponds to CURLOPT_URL in C. Firstly, uppercase letters are annoying to type and read, so we have mapped them to lower case letters in R. We have also removed the prefix "CURLOPT_" since we know the context in which they option names are being used. And lastly, any option names that have a _ (after we have removed the CURLOPT_ prefix) are changed to replace the '_' with a '.' so we can type them in R without having to quote them. For example, combining these three rules, "CURLOPT_URL" becomes url and CURLOPT_NETRC_FILE becomes netrc.file. That is the mapping scheme.

关于RCurl - bool 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17119449/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com