0
votes

I'm have some problems to use webclient.

When I try it:

var client = new WebClient();
client.Credentials = new NetworkCredential("intranet.homolog", "S3br@32011", "na-sebrae");
var html = client.DownloadData("http://www.intranet.sebrae.com.br/noticias/todas-as-notícias/rss.aspx?estado=");

I get an error (401).

This url returns xml feed, and, when I access it into browser, I login normally.

This user, and password are real.

Somebody have some ideia to I access it with the webclient?

2
401 = HTTP error for Unautorized access to a web page, check your credentials - Shai
I'd also check your URL. Ending with "?estado=" seems wrong. If supplying a 'state' parameter it probably ought to have a value e.g. ".../rss.aspx?estado=nuevo" - Grhm

2 Answers

1
votes

Here's my guess: you're misusing the NetworkCredential constructor

The correct syntax is

public NetworkCredential(
    string userName,
    string password,
    string domain
)

First username, then password, then domain - you got yours all wrong.

Try the following:

var client = new WebClient();
client.Credentials = new NetworkCredential("na-sebrae", 
                                           "S3br@32011",  "intranet.homolog");
var html = client.DownloadData("http://www.intranet.sebrae.com.br" +
                               "/noticias/todas-as-notícias/rss.aspx?estado=");
1
votes

I too get same error. The same link work better in browser but but giving 401 exception for WebClient.

    string url = "http://www.intranet.sebrae.com.br/noticias/todas-as-notícias/rss.aspx?estado=";
    var webClient = new WebClient();

    webClient.Credentials = CredentialCache.DefaultCredentials;

    byte[] html = webClient.DownloadData(fileAbsoluteUri);