I am trying to make a cURL call to download a CSV file and I’m getting back the login page html. Here is the code:
WebRequest myRequest = WebRequest.Create("https://website.com/medias/823533/events.csv");
myRequest.Credentials = new NetworkCredential("username", "password");
myRequest.Method = "GET";
myRequest.PreAuthenticate = true;
// Return the response.
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream());
string result = sr.ReadToEnd();
sr.Close();
Console.WriteLine(result);
Console.ReadLine();
Is there a simple cURL method in C#? This doesn’t seem to be working no matter what I try.
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 incase someone else runs into this: