Strange Error - WebClient DownloadData

  • Thread starter Thread starter Dave Starman
  • Start date Start date
D

Dave Starman

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.WebException' 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.WebClient

' Download the home page data.
Console.WriteLine(("Downloading " + remoteUrl))

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

' !!!!!!!!!! THIS LINE CAUSES THE ERROR !!!!!!!!!!!!!!!
Dim myDatabuffer As Byte() = myWebClient.DownloadData(remoteUrl)

' Display the downloaded data.
Dim download As String =
System.Text.Encoding.ASCII.GetString(myDatabuffer)

Console.WriteLine(download)
Console.WriteLine("Download successful.")
 
Dave,

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

Cor
 
Cor,

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

-Dave
 
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
 
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
 
Dave

I tried this
\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.IsMdiContainer = 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
 
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" ?>
<configuration>
<identity impersonate="true" />
</configuration>
 

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


Back
Top