Visual Basic download file https

0

Using the following code:

Try
    Dim fileToDownload As String = "miArchivo"
    Dim downloadPath As String = Directory.GetCurrentDirectory() & "\data\downloads\"
    Dim currDate = DateTime.Now.ToString("dd-MM-yyyy HH.mm.ss").ToString
    Dim downloadedFileName As String = "miArchivoDescargado" & currDate & ".xml"
    Dim downloadString = downloadPath & downloadedFileName


    My.Computer.Network.DownloadFile(fileToDownload, downloadString, "a", "b", True, 2500, True)


    Return True
Catch ex As Exception
    MsgBox("No se ha podido descargar la información desde la web debido al siguiente error: " & ex.Message)
    Return False
End Try

I can easily download a file hosted on the specified path as long as I do not use the secure connection, that is, https.

When trying to download using httpS, the following error appears: "The connection is terminated, unexpected sending error."

How is the secure connection valid using "DownloadFile"?

    
asked by Mark 06.08.2017 в 12:50
source

1 answer

1

Do not use Network.download use another as webclient, for example:

Dim fileToDownload As String = "miArchivo"
    Dim downloadPath As String = Directory.GetCurrentDirectory() & "\data\downloads\"
    Dim currDate = DateTime.Now.ToString("dd-MM-yyyy HH.mm.ss").ToString
    Dim downloadedFileName As String = "miArchivoDescargado" & currDate & ".xml"
    Dim downloadString = downloadPath & downloadedFileName

     WebClient wc = new WebClient();
            wc.UseDefaultCredentials = false;

//por si necesitas conectarte con algun usuario o contraseña
            CredentialCache creds = new CredentialCache(); 
            creds.Add(new Uri(url), "Basic",new NetworkCredential(username, password, domain));
//de lo contrario borra esto

            wc.Credentials = creds;
            wc.Headers.Add(HttpRequestHeader.UserAgent,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;");
            //wc.Headers["Accept"] = "/";

            wc.DownloadFile(fileToDownload ,downloadString  );
    
answered by 06.08.2017 в 13:01