Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello:

 

I am attempting to download a file from an https site using the WebClient class. I am able to successfully plug the url with

 

the uid and pwd in the url from IE and it works fine. However when I use this same string from VB.Net I get an

 

exception:

 

"The underlying connection was closed: Unable to connect to the remote server."

 

I wasn't sure if perhaps I needed additional info for proxy settings or how to set them or if there is just something wrong

 

with my code.

 

Private Sub btnGetFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetFile.Click

 

Dim strURL As String = "https://myUserName:myPassword@http://www.theSite.com/files/all/test/"

Dim strFileSource As String = "TestTmp.Dat"

Dim strFileDestination As String = strFileSource

Dim strWebResource As String = strURL + strFileSource

Dim wc As New WebClient()

 

'I get the same error with or without this line.

'wc.Credentials = CredentialCache.DefaultCredentials

 

Try

wc.DownloadFile(strWebResource, strFileDestination)

Catch ex As System.Exception

lblStatus.Text = ex.Message

End Try

 

End Sub

 

Any help anybody could provide with this would be greatly apprecieated.

 

Thanks,

Al

  • 2 months later...
Posted

I am not using an HTTPS connection, but I found that I needed to set username and password by setting Credentials, and set up a proxy, by calling System.et.GlobalProxySelection.Select.

 

Try something like this:

 

System.Net.WebClient client = new System.Net.WebClient();

System.Net.GlobalProxySelection.Select = new System.Net.WebProxy("myproxy.company.com:8080");

client.Credentials = new System.Net.NetworkCredential("username","password");

client.DownloadFile("http://passwordprotectedsite.com/file.txt","c:\\file.txt");

 

Hope this helps,

 

Richard

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...