I need to access a webservice from a client to authenticate and get an access token, when I use credentials via java or google arc everything works perfectly and I get the access token but in C # I'm not getting it, it returns error 401 unauthorized always.
below the code I'm using.
using (WebClient client = new WebClient())
{
client.UseDefaultCredentials = true;
client.Headers.Add("Authorization", "Basic " +
Convert.ToBase64String(Encoding.UTF8.GetBytes("myUser:MyPassword")));
string response = client.UploadString("https://api.myclient.us/authenticate",
"");
return response;
}
I tried to change this code with several examples on the net but I still have the same error, do I have to change something in web.config, or something in the project?