I need to perform a cURL request to grab a CSV file from the web. I’ve never used cURL before and so far the stuff I have seen via google doesn’t seem to make sense:
the cURL call needs to look like this:
curl --user username:password http://somewebsite.com/events.csv
the code I am trying to use ( i use this to grab basic auth XML files)
string URL = "http://somewebsite.com/events.csv";
string Username = "username";
string Password = "password";
WebClient req = new WebClient();
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri(URL), "Basic", new NetworkCredential(Username, Password));
req.Credentials = myCache;
string results = null;
results = Encoding.UTF8.GetString(req.DownloadData(URL));
This just gives me back the html for a login screen so the authentication is not happening.
I found the issue. Apparently the request fails when you pass an
@sign ( like in the email username ) in the username field so it must be Converted to a base 64 string. Here is the code just in case someone else runs into this: