我有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请求中传递用户名和密码
您也应该设置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"
Run Code Online (Sandbox Code Playgroud)