473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

WebClient problem

Dear All,

I am using WebClient in my Visual Studio .Net 2003 project to download
an image from the Internet. The following is my function:

C# Code:

public static bool downloadFile(string URL, ref string fileName)
{
bool result = true;
System.Net.WebClient webClient = new System.Net.WebClient();
try
{
string[] temp;
temp = URL.Split('/');
fileName = Application.StartupPath + "\\tempimage\\" +
temp[temp.Length-1];

webClient.Credentials =
System.Net.CredentialCache.DefaultCredentials;
webClient.DownloadFile(URL, fileName);
}
catch (System.Exception ex)
{
result = false;
}
finally
{
webClient.Dispose();
}
return result;
}
The above function works most of t he time but sometimes I got the
following exception:

System.Net.WebException: The underlying connection was closed: The
server committed an HTTP protocol violation.

at System.Net.HttpWebRequest.CheckFinalStatus()

at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)

at System.Net.HttpWebRequest.GetResponse()

at System.Net.WebClient.DownloadFile(String address, String fileName)

at WindowsApplication4.Form11.downloadFile(String URL, String fileName)
in g:\project\visual studio
projects\windowsapplication4\windowsapplication4\f orm11.cs:line 392

Do anyone know what wrong is the function?

Thanks very much for your help.

Regards,
Vincent

Mar 20 '06 #1
1 6264
Thus wrote vi*****@gmail.com,
Dear All,

I am using WebClient in my Visual Studio .Net 2003 project to download
an image from the Internet. The following is my function:

C# Code:

public static bool downloadFile(string URL, ref string fileName)
{
bool result = true;
System.Net.WebClient webClient = new System.Net.WebClient();
try
{
string[] temp;
temp = URL.Split('/');
fileName = Application.StartupPath + "\\tempimage\\" +
temp[temp.Length-1];
webClient.Credentials =
System.Net.CredentialCache.DefaultCredentials;
webClient.DownloadFile(URL, fileName);
}
catch (System.Exception ex)
{
result = false;
}
finally
{
webClient.Dispose();
}
return result;
}
The above function works most of t he time but sometimes I got the
following exception:

System.Net.WebException: The underlying connection was closed: The
server committed an HTTP protocol violation.

at System.Net.HttpWebRequest.CheckFinalStatus()

at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)

at System.Net.HttpWebRequest.GetResponse()

at System.Net.WebClient.DownloadFile(String address, String fileName)

at WindowsApplication4.Form11.downloadFile(String URL, String
fileName) in g:\project\visual studio
projects\windowsapplication4\windowsapplication4\f orm11.cs:line 392

Do anyone know what wrong is the function?


Probably nothing. "The server committed an HTTP protocol violation" indicates
that something in the response isn't HTTP 1.1 compliant. See http://blogs.msdn.com/mflasko/archiv...02/488370.aspx
for more details and a possible work around.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Mar 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: ptass | last post by:
Hi I've installed win2k3 sp1 on a machine where an openRead on any given file was previously working. After installation, I get a webException as follows... ..message "An exception occurred...
2
by: Gary Short | last post by:
Hello group, I was wondering if anyone here could help me with an odd WebClient problem. When I run the following code: WebClient aWebClient = new WebClient(); Byte aBA =...
2
by: Max Gattringer | last post by:
Hi, I've got a little problem with the WebClient, I always get a failure while debugging this code: private void menuItem2_Click(object sender, System.EventArgs e) { NameValueCollection...
1
by: Nurchi BECHED | last post by:
Hello, everyone. I am stuck with the following: There is a webpage which contains a webform, which contains text fields, and submits the data from current page to another one. I need to...
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
1
by: Cc | last post by:
i try to download a file using web client but keep getting exception on receive WebClient1.DownloadFile("http://www.testing.net/cgi-bin/test/test.pl?action=download", "c:\\aa.txt")
6
by: Giovanni | last post by:
Hi Guys, Really strange problem I am experiencing... I have setup a virtual directory with Read Only permissions on an ISA/IIS server (SBS 2003). In that virt. dir., I placed 1 file...
4
by: Lehel Kovach | last post by:
I'm having a problem with the WebClient object. When I post data to certain sites, it will receive a command from the webserver (object moved) and continue to the next link by downloading that. ...
0
by: larsergud | last post by:
Hi all, This code genearates a error saying "could not connect to remote server", but only by the webclient call inside the loop, eventhough it's the exact same calls? any suggestions? ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.