VB.NET 2005 WebClient file download via HTTPS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chad T

    VB.NET 2005 WebClient file download via HTTPS

    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_Serve r/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?


    '************Co de starts here
    Imports System.IO
    Imports System.Net
    Imports System.Text

    Module Module1
    Sub Main()
    Dim fullfiledownloa d 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"

    fullfiledownloa d = fileurl & filedownload
    filefullpath = filepath & newfilename

    Dim wc As New WebClient
    Dim myCredentials As New NetworkCredenti al(userid,
    userpassword)
    wc.Credentials = myCredentials
    wc.DownloadFile (fullfiledownlo ad, filefullpath)
    End Sub
    End Module
  • Patrice

    #2
    Re: VB.NET 2005 WebClient file download via HTTPS

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



    --

    "Chad T" <ChadT@discussi ons.microsoft.c oma écrit dans le message de news:
    8D01600A-5214-4704-AD4A-3B5ACDDC102D@mi crosoft.com...
    >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_Serve r/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?
    >
    >
    '************Co de starts here
    Imports System.IO
    Imports System.Net
    Imports System.Text
    >
    Module Module1
    Sub Main()
    Dim fullfiledownloa d 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"
    >
    fullfiledownloa d = fileurl & filedownload
    filefullpath = filepath & newfilename
    >
    Dim wc As New WebClient
    Dim myCredentials As New NetworkCredenti al(userid,
    userpassword)
    wc.Credentials = myCredentials
    wc.DownloadFile (fullfiledownlo ad, filefullpath)
    End Sub
    End Module

    Comment

    Working...