allend2010 Posted September 5, 2003 Posted September 5, 2003 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 Quote
*Gurus* Derek Stone Posted September 6, 2003 *Gurus* Posted September 6, 2003 This is a known issue with .NET 1.0 and Internet Explorer. I don't remember if .NET 1.1 includes a fix. You'll have to check and see. Quote Posting Guidelines
rjonas Posted November 11, 2003 Posted November 11, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.