通过 httr::config(ssl_options = c(LIST OF SEVERAL CURLSSLOPT_) ) 指示几个curl选项

问题描述 投票:0回答:1

如何通过httr::config(ssl_options = ...)传递

几个
libcurl选项?

我的主要目标是指出这两个参数:

CURLSSLOPT_AUTO_CLIENT_CERT
CURLSSLOPT_NATIVE_CA
,以便依赖 schannel 默认行为来建立 ssl 双重身份验证。

非常感谢您的任何提示和建议。

✅ 例如,以下将正确启用 schannel,并且 ssl 尝试依赖本地客户端证书':

urll = "https://www.google.com"
    
response <- httr::GET(
        urll,
        httr::config(use_ssl = T ,followlocation = T
             ,  ssl_options = c("CURLSSLOPT_AUTO_CLIENT_CERT"=32)
                , verbose = T ) )

根据日志,会话能够使用客户端证书(即日志表明

* schannel: enabled automatic use of client certificate

但是我不知道如何传递几个“ssl_options”?

❌ 下面的示例将导致错误:

         response <- httr::GET(
                urll,
                httr::config(use_ssl = T ,followlocation = T
                     ,  ssl_options = c("CURLSSLOPT_AUTO_CLIENT_CERT"=32 
                                      , "CURLSSLOPT_NATIVE_CA" = 16)  
                        , verbose = T ) )

    Error: curl::handle_setopt(handle, .list = req$options) : 
      Value for option ssl_options (216) must be a number.

有什么方法可以用

httr::config(ssl_options = [??])
向 libcurl 指示几个“ssl_options”?

r curl ssl-certificate libcurl httr
1个回答
0
投票

根据

httr::curl_docs("ssl_options")
#> Please point your browser to the following url:
#> http://curl.haxx.se/libcurl/c/CURLOPT_SSL_OPTIONS.html

它是一个位掩码,您可以尝试

bitwOr()
或简单地添加相关符号来设置位:

httr_cfg <- 
  httr::config(
    use_ssl = TRUE,
    followlocation = TRUE,
    verbose = TRUE,
    ssl_options = 
      curl::curl_symbols("CURLSSLOPT_AUTO_CLIENT_CERT")$value +
      curl::curl_symbols("CURLSSLOPT_NATIVE_CA")$value
  )

httr_cfg
#> <request>
#> Options:
#> * use_ssl: TRUE
#> * followlocation: TRUE
#> * verbose: TRUE
#> * ssl_options: 48

urll = "https://www.google.com"
response <- httr::GET(urll, httr_cfg)

创建于 2024 年 12 月 11 日,使用 reprex v2.1.1

© www.soinside.com 2019 - 2024. All rights reserved.