Possible Duplicate:
Reading information from a password protected site
I have a webservice that provides data in csv form, based on the url you use to access it. i.e. http://sever.com/parameter1 returns a csv for parameter 1, http://sever.com/parameter1 returns a csv for parameter 2, etc. When I first access the site in my browser, I type in a username and password and can then access any data I want.
The problem arises when I try to import that data into R. I tried this function:
readLines('http://sever.com/parameter1')
But got the following error:
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") : cannot open: HTTP status was '401 Unauthorized'
Of course, this is because R doesn’t know to pass my username and password along with the request. How do I define these additional parameters in R? Is there any way to add a cookie to the request or something?
Thank you.
/edit: The answer here (different question wording wasn’t picked up by SO) worked for me:
Reading information from a password protected site
If anyone else has any other advice, please let me know.
Why don’t you use curl to grab the file? That way you can set http headers for username and password:
There is a curl library for R