473,802 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange Error - WebClient DownloadData

Hello,

I am trying to download web data into my current application. Failing
many attempts I tried to run the sample from the MS Help files with no
luck. If I create a new solution and put the sample code on a button
then it works. However, when do the same on a new form in my existing
solution then I get following error. Could there be some global
settings in my application that are causing problems?

Thanks in advance,

-Dave
Error:
-----------------------------------------------
An unhandled exception of type 'System.Net.Web Exception' occurred in
system.dll

Additional information: An exception occurred during a WebClient
request.
Sample Code:
-----------------------------------------------
Dim remoteUrl As String = "http://www.msn.com"

' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebC lient

' Download the home page data.
Console.WriteLi ne(("Downloadin g " + remoteUrl))

' Downloads the Web resource and saves it into a data buffer.

' !!!!!!!!!! THIS LINE CAUSES THE ERROR !!!!!!!!!!!!!!!
Dim myDatabuffer As Byte() = myWebClient.Dow nloadData(remot eUrl)

' Display the downloaded data.
Dim download As String =
System.Text.Enc oding.ASCII.Get String(myDatabu ffer)

Console.WriteLi ne(download)
Console.WriteLi ne("Download successful.")
Nov 21 '05 #1
6 4380
Dave,

I think that for most of us that is impossible to see without the code that
generates the error.

Cor

"Dave Starman" <da*********@cz echbeads.com>
Hello,

I am trying to download web data into my current application. Failing
many attempts I tried to run the sample from the MS Help files with no
luck. If I create a new solution and put the sample code on a button
then it works. However, when do the same on a new form in my existing
solution then I get following error. Could there be some global
settings in my application that are causing problems?

Thanks in advance,

-Dave
Error:
-----------------------------------------------
An unhandled exception of type 'System.Net.Web Exception' occurred in
system.dll

Additional information: An exception occurred during a WebClient
request.
Sample Code:
-----------------------------------------------
Dim remoteUrl As String = "http://www.msn.com"

' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebC lient

' Download the home page data.
Console.WriteLi ne(("Downloadin g " + remoteUrl))

' Downloads the Web resource and saves it into a data buffer.

' !!!!!!!!!! THIS LINE CAUSES THE ERROR !!!!!!!!!!!!!!!
Dim myDatabuffer As Byte() = myWebClient.Dow nloadData(remot eUrl)

' Display the downloaded data.
Dim download As String =
System.Text.Enc oding.ASCII.Get String(myDatabu ffer)

Console.WriteLi ne(download)
Console.WriteLi ne("Download successful.")

Nov 21 '05 #2
Cor,

Please see my original post. The code is under the Sample Code heading.

-Dave

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3
Dave.

Sorry, I had not seen it, however as you told this does work in a single
module, so where do you place it in your application?

Cor
Nov 21 '05 #4
I set up a form in a *new* application with one button and included the
code from my first post. When I click the button it returns the website
code as it should.

Next, I opened my existing (MDI) solution and added the form to the
root. I set the form as the start object (tried calling the form from
the mdi app as well) and ran the application. When I click the button I
receive the error message when the download is attempted.

-Dave

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5
Dave

I tried this
\\\
Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Me.IsMdiContain er = True
Dim frm2 As New Form2
frm2.MdiParent = Me
frm2.Show()
End Sub
///
And in Form2 in the button event the download code,

That works perfect

Cor
"Dave Starman" <da*********@cz echbeads.com> schreef in bericht
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
I set up a form in a *new* application with one button and included the
code from my first post. When I click the button it returns the website
code as it should.

Next, I opened my existing (MDI) solution and added the form to the
root. I set the form as the start object (tried calling the form from
the mdi app as well) and ran the application. When I click the button I
receive the error message when the download is attempted.

-Dave

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #6
After further research I found a setting in the app.config. The
impersonate property was set to true. When I deleted this tag,
everything started to work.

I don't understand why that would cause a problem. Any ideas?

-Dave
------APP.CONFIG FILE causes the errors--------
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<identity impersonate="tr ue" />
</configuration>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #7

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

Similar topics

1
1416
by: Christopher Ireland | last post by:
Hi -- I'm not looking for a definitive solution here, just some pointers in the right direction. I have a very simple UserControl in an HTML page enclosed within <object> tags virtually identical to this one: http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=187 The only difference is that I have added a public method:
1
3261
by: yyy | last post by:
This problem bothers me for a long time: I use WebClient.DownloadData in order to read text from an HTML document this way: WebClient c = new WebClient(); string html= ASCIIEncoding.Default.GetString(c.DownloadData("http://www.test.com")); When I run the code, I get this error message after a few seconds:
1
2099
by: Shiju Poyilil | last post by:
Hello everybody, I am using the the below mentioned packages for sending the mail, but when i assign the read file to a byte array " barr = wc.DownloadData(url)" I get an error "The remote server returned an error: (401) Unauthorized." ,so can nayone of you tell me waht could be the reason for the error and how it can be rectified. ************************* code for your perusal
2
4899
by: Rags | last post by:
Hi We are creating a web application using .NET which renders some reports. The reports are created in MS Reporting Services and can be accessed by typing in a URL with the required parameters in a browser. The reports are getting rendered fine if I type the URL in the browser. Within the web application, however, we are using the webclient.downloaddata method to extract the HTML by specifying the URL and rendering within the .NET...
8
9036
by: DEWright_CA | last post by:
Why does WebClient.DownloadFile loose my completed path? Ok, I have a function in my app then when my button is clicked it checks to see if the files come from a local drive or a http address. The portion of the code that pulls from the drive works great, but when the http address is active it changes the originating path to my C:\Windows\System32 folder instead of the proper path. I keep the path as a field on my form so I am certain...
4
3685
by: Crirus | last post by:
Hi there! Fisrt the question: there is a ay to make the DownloadData when I want? I have a WebClient class I use myWebClient.DownloadData(remoteUrl) to connect to internet server All this in a separate thread for asincron pourpose Anyway, when I try to close the application before DownloadData returned, it wont stop this thread.
1
6497
by: Mad Scientist Jr | last post by:
For some reason I can't get a WebClient to access an outside URL from behind our firewall. The code works when it runs outside the firewall. I turned on windows authentication in the web.config <authentication mode="Windows" /> and set up IIS to not allow anonymous access. My browser is set up to auto detect the proxy server, so IE/Firefox can access outside pages, so I added code to auto-detect the proxy server.
0
1435
by: aferriere | last post by:
Hi I am getting a System.Net.WebException -- >The remote server returned an error: (501) Not Implemented when I try to read the contents from http://www.ourcommunity.com.au/member/directory_details.do?orgId=319 Other urls which I have tried work fine. I have tried using both WebRequest and WebClient
1
1782
by: jmk | last post by:
I'm trying to use an external SMS-service through .NET Framework 1.1 and using the webClient.DownloadData(strMessage) method. The strMessage is a string consisting the parameters to send a message, and the return-value to the DownloadData method is to be a status code for the requested message. However, using this method causes a connection-timeout from the SMS-service. Sending the same strMessage using reponse.redirect(strMessage) sends...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.