Using cURL behind password site


#1

I'm having trouble downloading a csv file saved behind a site with a username and password. I think I am doing something wrong with the handle, but don't understand curl enough to fix it.

library(curl)

url <- "https://xxx.com/admin/california_initial_applications.csv"

h <- new_handle()

handle_setopt(handle = h,
httpauth = 1,
userpwd = "user123:hunter2")

req <- curl_fetch_memory(url, handle = h)

When it executes, I'm getting a list of 6 elements and the status_code element is 401.

Thanks for any insights


#2

you could try with {httr} but I think it is the same:

library(httr)
GET(url, authenticate(user, password))