I download files from a HTTPS Secure Webpage.
So I use a HTTPSecureSocket to do it. I download files normally, I set it with SetRequest Header passing the required Cookie in order to download files, My code is this:
[code] Dim SAVEFILE as FolderItem = SpecialFolder.Documents.Child(“CFDieBrain”).Child(TipoFacturaSol).Child(RFCInvestigado).Child(Year).Child(Mes).Child(EmisorFiltrado).Child(FileName.Uppercase+".xml")
//ESPECIFICAMOS LOS DATOS DEL SOCKET SEGURO O COMO LO LLAMAN EN VB.NET "WEBCLIENT"*******//
downloadSocket.Secure = True 'HABILITAMOS LA OPCION SEGURA, DE LO CONTRARIO SERIA UN SOCKET SIMPLE
downloadSocket.Port = 443 'ESPECIFICAMOS EL PUERTO DE CONEXIN, EN ESTE CASO SER EL 443
downloadSocket.ConnectionType = 3 'ESPECIFICAMOS EL TIPO DE CONEXIN
downloadSocket.SetRequestHeader(“Accept”, "/") 'ACEPTAMOS LOS SIGUIENTES CARACTERES
downloadSocket.SetRequestHeader(“Accept-Encoding:”,“gzip,deflate,sdch”) ’ ACEPTAMOS LOS SIGUIENTES TIPOS DE CODIFICACIN
downloadSocket.SetRequestHeader(“User-Agent:”,“Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36”) 'ESTABLECEMOS LOS DIFERENTES TIPOS DE NAVEGADOR A SOPORTAR
downloadSocket.SetRequestHeader(“Connection”, “keep-alive”) ’ ESTABLECEMOS QUE QUEREMOS MANTENER VIVA LA CONEXIN
downloadSocket.SetRequestHeader(“Accept-Language”, “en-US,en;q=0.8”) 'ESTABLECEMOS EL TIPO DE LENGUAJE
downloadSocket.SetRequestHeader(“Cookie”, CookieName) 'Y FINALMENTE LA PARTE MAS “BELLA”, HACEMOS LA PETICIN AL HEADER CON LA COOKIE GUARDADA “COOKIENAME” PARA IDENTIFICARNOS EN EL SERVIDOR
//SI EL ENLACE HA SIDO DESCARGADO EXITOSAMENTE ATRAVES DEL SOCKET, ENTONCES MOSTRAR UN MENSAJE DE EXITO.
if downloadSocket.Get(enlace, SAVEFILE, 30) = True then
Msgbox “Successfully Downloaded”
End If
[/code]
Where downloadSocket = HttpSecureSocket
And Enlace = URL to Download
SAVEFILE = Folder to download the file
And in SetRequestHeader “Cookie” is the name of the cookie.
But the real problem starts with when I download XML files as it normal, sometimes I download the normal XML and sometimes I download details but with a little detail.
At First of the code XML it writes THREE EMPTY LINES before the normal code <xml bla bla bla bla
I think that I forgetting something in SetRequest Header.
And Also I dunno how to set in Accept-Language to Spanish-Spain or Spanish-Mexico instead of en-US,en;q=0.8
The idea here is that I wanna download all the XML but without these three empty lines.
Am I wrong?
Thanks