VB.NET 2005 WebClient file download via HTTPS

G

Guest

I am very new to VB.Net (most of my experience is with vbscript)
My goal is to create a executable to download files from a HTTPS server.
I have to pass the credentials to the https server.

The code below works fine on our IIS server configured for https but when I
connect to a remote server running "IBM_HTTP_Server/2.0.47.1-PK29827
Apache/2.0.47 (Win32) Server" The error I get is Unauthorized...

My Error: The remote server returned an error: (401) Unauthorized.

How can I fix this so it works on any https server... or is there a better
way to do this?


'************Code starts here
Imports System.IO
Imports System.Net
Imports System.Text

Module Module1
Sub Main()
Dim fullfiledownload As String
Dim filefullpath As String

Dim fileurl As String = "https://someserver/"
Dim filedownload As String = "fcs_hail_data_06.txt"
Dim newfilename As String = "Igotit.TXT"
Dim filepath As String = "C:\"
Dim userid As String = "userid"
Dim userpassword As String = "password"

fullfiledownload = fileurl & filedownload
filefullpath = filepath & newfilename

Dim wc As New WebClient
Dim myCredentials As New NetworkCredential(userid,
userpassword)
wc.Credentials = myCredentials
wc.DownloadFile(fullfiledownload, filefullpath)
End Sub
End Module
 
P

Patrice

Does it work "by hand" with these credentials ? It would likely allows to
see if the credentials and/or the file permission are not correct or if this
is a problem with the code...
 

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

Top