System.Net.WebException Error - Please help

S

spdude

I have written a windows app to request a file from www.hotmail.com and
i get the following error:

************* Exception Text **************
System.Net.WebException: The remote server returned an error: (407)
Proxy Authentication Required.

My code:

private void Download(String strFinalURL)
{
WebRequest objWebRequest;
WebResponse objWebResponse;
FileStream objFileStream;
BufferedStream objBufferedStream;
Byte[] b = new Byte[1024];
//Byte[] b = new Byte[8192];
int iRead = 1;

objWebRequest = WebRequest.Create(strFinalURL);
objWebRequest.Credentials = CredentialCache.DefaultCredentials;

objWebResponse = objWebRequest.GetResponse();
this.lblSize.Text = objWebResponse.ContentLength.ToString() + "
Bytes";

objBufferedStream = new
BufferedStream(objWebResponse.GetResponseStream());
//String strOutputFileName = TEMP_DIR + TEST_FILE + EXT;
String strOutputFileName = TEMP_DIR + this.txtFileNameLocal.Text +
"." + this.txtExt.Text;
objFileStream = new FileStream(strOutputFileName,
FileMode.OpenOrCreate,
FileAccess.Write);

long streamLen = objWebResponse.ContentLength;
float fLen = (float)streamLen;
long count = 0;

Console.Write("File downloaded");
objBufferedStream.Close();
objFileStream.Close();

}
 
A

AnkitAsDeveloper

Hey SP Dude,

I think u r accessing Internet using proxy server. Am i right?

If i'm, do sd followd:

WebRequest objWebRequest;
WebResponse objWebResponse;

//****************New code -************
Net.WebProxy aProxy = new Net.WebProxy();
aProxy.Address = new Uri(serverAddress);
aProxy.Credentials = new System.Net.NetworkCredential(username,
password, domain);

objWebRequest.Proxy = aProxy;
objWebResponse.Proxy = aProxy
//*********** End of new code*******

The above will surly work....

Regards,

Ankit Jain,
http://www.ankitjain.info/
 
S

spdude

Now I am getting this error:

System.Security.SecurityException: Request for the permission of type
System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 failed.

Any help?
 
A

AnkitAsDeveloper

R u on dialup connection ofr working for an organization. It's the
server address for using internet.U can check it in

"Control Panel > Internet Options > Connections > Lan Settings... "

Specifies to connect to the Internet through a proxy server by using
the settings you specify. A proxy server acts as an intermediary
between your internal network (intranet) and the Internet, retrieving
files from remote Web servers.


Ankit Jain, [http://www.ankitjian.info/ankit/]
 
A

AnkitAsDeveloper

R u on dialup connection ofr working for an organization. It's the
server address for using internet.U can check it in


"Control Panel > Internet Options > Connections > Lan Settings... "


Specifies to connect to the Internet through a proxy server by using
the settings you specify. A proxy server acts as an intermediary
between your internal network (intranet) and the Internet, retrieving
files from remote Web servers.


Ankit Jain, [http://www.ankitjain.info/ankit/]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top