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

Kus*_*tel 5 curl r

我有curl请求是工作文件,如下所示:

curl -XGET "https://xxxx.com/xxx" -u "username:password"

我是怎么想用curlR中的包来做的

我有以下代码,

library(curl) clCall <- new_handle(url = 'https://xxxx.com/xxx') handle_setopt(clCall, customrequest = "XGET")

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

Art*_*sov 6

您也应该设置httpauthuserpwd选项:

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"
Run Code Online (Sandbox Code Playgroud)