加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

如何在curl R中传递new_handle中的用户名和密码

发布时间:2020-12-14 01:05:58 所属栏目:Linux 来源:网络整理
导读:我有curl请求是工作文件,如下所示: curl -XGET“https://xxxx.com/xxx”-u“用户名:密码” 我是怎么想用R中的curl包来做的 我有以下代码, 库(卷曲) ?clCall - new_handle(url ='https://xxxx.com/xxx') ?handle_setopt(clCall,customrequest =“XGET”) 现
我有curl请求是工作文件,如下所示:

curl -XGET“https://xxxx.com/xxx”-u“用户名:密码”

我是怎么想用R中的curl包来做的

我有以下代码,

库(卷曲)
?clCall< - new_handle(url ='https://xxxx.com/xxx')
?handle_setopt(clCall,customrequest =“XGET”)

现在我不知道如何在这个curl请求中传递用户名和密码

解决方法

您也应该设置httpauth和userpwd选项:

h <- curl::new_handle()
curl::handle_setopt(
    handle = h,httpauth = 1,userpwd = "user:passwd"
)
resp <- curl::curl_fetch_memory("https://httpbin.org/basic-auth/user/passwd",handle = h)
jsonlite::fromJSON(rawToChar(resp$content))
#> $authenticated
#> [1] TRUE
#> 
#> $user
#> [1] "user"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读