R中的curl请求

R中的curl请求,r,curl,R,Curl,卷曲要求: curl -i -H "Accept: application/json" -H "Content-Type: application/json" -d '{"username":"emailId","password":"passwrd"}' -X POST https://central.vizury.com/-/api/login res: 我需要在R中执行相同的操作: 这就是我迄今为止所尝试的: h <- basicHeaderGatherer() loginUrl

卷曲要求:

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -d '{"username":"emailId","password":"passwrd"}' -X POST https://central.vizury.com/-/api/login
res:

我需要在R中执行相同的操作:

这就是我迄今为止所尝试的:

h <- basicHeaderGatherer()

loginUrl <- "https://central.vizury.com/-/api/login"
params <- list('username' = 'username',
               'password' = 'password')
loginRes <- postForm(loginUrl, .params=params, style="POST",  .opts=curlOptions(headerfunction=h$update, verbose=TRUE))
print("loginres")
print(loginRes)

h使用
curl
package的示例:

h <- curl::new_handle()
login_url <- 'https://central.vizury.com/-/api/login'
curl::handle_setform(
    handle = h,
    username = 'username',
    password = 'password'
)
resp <- curl::curl_fetch_memory(login_url, handle = h)
message(resp$status_code)
jsonlite::fromJSON(rawToChar(resp$content))
h
h <- curl::new_handle()
login_url <- 'https://central.vizury.com/-/api/login'
curl::handle_setform(
    handle = h,
    username = 'username',
    password = 'password'
)
resp <- curl::curl_fetch_memory(login_url, handle = h)
message(resp$status_code)
jsonlite::fromJSON(rawToChar(resp$content))