Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The remote server returned an error: (401) Unauthorized

I'm trying to get the html code of certain webpage, I have a username and a password that are correct but i still can't get it to work, this is my code:

private void buttondownloadfile_Click(object sender, EventArgs e)
{
    NetworkCredentials nc = new NetworkCredentials("?", "?", "http://cdrs.globalpopsvoip.com/0000069/20091229/20091228_20091228.CDR");   
    WebClient client = new WebClient();

    client.Credentials = nc;
    String htmlCode = client.DownloadString("http://cdrs.globalpopsvoip.com/0000069/20091229/20091228_20091228.CDR");

    MessageBox.Show(htmlCode);
}

The MessageBox is just to test it, the problem is that every time I get to this line:

String htmlCode = client.DownloadString("http://cdrs.globalpopsvoip.com/0000069/20091229/20091228_20091228.CDR");

I get an exception:

The remote server returned an error: (401) Unauthorized.

How do I fix this?

like image 973
Zaidman Avatar asked Jan 10 '10 21:01

Zaidman


People also ask

What is a 401 unauthorized error?

The HyperText Transfer Protocol (HTTP) 401 Unauthorized response status code indicates that the client request has not been completed because it lacks valid authentication credentials for the requested resource.

How do you remove 401 unauthorized access is denied due to invalid credentials?

In the Authentication Methods dialog, enable either the Integrated Windows authentication box or Basic authentication (password is sent in clear text), and clear all other authentication options for Authentication access.


1 Answers

In my case client.UseDefaultCredentials = true; did the trick.

like image 80
kad81 Avatar answered Sep 28 '22 04:09

kad81