Is it possible to create a WebRequest w a username and password

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi all:

I am trying to retrieve some info from a file on my web server, but cannot
get the file due to teh security. Is it possible to create a URL and web
request that uses a valid username/apssword to get the file? I was reading
about teh UriBuilder class, however I don't see a constructor for a wb
request that takes the UriBuilder....

Code is below, thanks for any and all input...

John.

HttpWebRequest x_req;

HttpWebResponse x_response;

StreamReader x_reader;

try

{

//NOTE: gotta enable anonymous access for the directory for this to work!!!

x_req = (HttpWebRequest)WebRequest.Create(http://server/file.xml);

x_response = (HttpWebResponse)x_req.GetResponse();

x_reader = new StreamReader( x_response.GetResponseStream() );

while ( ( sReadLine = x_reader.ReadLine() ) != null )

{

//txtDebug.Text += sReadLine;

sInput += sReadLine;

}

}

catch( WebException WebEx)

{

txtDebug.Text = WebEx.ToString();

}
 
If anyone's interested, here is the solution...

System.Net.NetworkCredential credentials = new System.Net.NetworkCredential
(<user>,<pw>,<domain>);
HttpWebRequest x_req;
HttpWebResponse x_response;
StreamReader x_reader;
try
{
x_req = (HttpWebRequest)WebRequest.Create("url");
x_req.Credentials = credentials;
 
Back
Top