i want to download a file (it’s a sqlite-db) from a htaccess-protected folder of my webserver to a folder.
It’s a https-site, so the HTTPSecureSocket seems to be the right choice. But how do i implement the username and password? how do i start the download? The xojo.doc did not show me the right direction.
This is where you pass your name/password. Also be sure to know what version of SSL/TLS you need to use also.
Good luck!
for example:
AuthenticationRequired Event:
Name = myUsername
Password = myPassword
Return True
In addition within the constructor of the HTTPSecureSocket I will generally set some other User Agent specific parameters. This can vary per platform/browser that you are wishing to emulate.
Self.SetRequestHeader("Accept", "*/*")
Self.SetRequestHeader("Accept-Encoding:","gzip,deflate,sdch")
Self.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")
Self.SetRequestHeader("Connection", "keep-alive")
Self.SetRequestHeader("Accept-Language", "en-US,en;q=0.8")
The following I also include in the same constructor to set my port information. Notice ConnectionType=3 (TLSv1.0).
One way to address this is to subclass the HTTPSecureSocket class and give it Username and Password properties. You can then set those before you connect and implement the event to take the username and password from them. If they aren’t filled in, you can return false.
Now i use this code to download a file via https from a protected site:
[code] Dim f As FolderItem
f = SpecialFolder.ApplicationData.Child(“UniFormis”)
f = f.Child(“uniformis.sqlite”)
dim downloadSocket As New HTTPSecureSocket
downloadSocket.SetRequestHeader(“Authorization”, "Basic " + EncodeBase64(“USERNAME” + “:” + “PASSWORD”))
if downloadSocket.Get(“https://PATH-TO-DOWNLOAD-FILE/uniformis.sqlite”, f, 30) = True then
MsgBox(“Download complete”)
end if[/code]
I do get a file every time i run this code, but the file is to small, so my sqlite-db is not working. i only get 47 bytes, the original-filesize is 124 Kbytes. I also reach the download-complete status.
I have tried 2 ways:
Drop a tcp-socket (with superclass HTTPSecureSocket) in my window and use the code above without the dim downloadSocket as new HTTPSecureSocket statement
Remove the tcp-socket from my window and create it with the dim downloadSocket as new HTTPSecureSocket Statement
Both methods download a file (ok, maybe they only create a file) and both do not drop an error-message.
Do i have to place a HTTPSecureSocket-Control on my windows to get this working?
i now made a separate download window, like in the xojo-examples. i placed a HTTPSecureSocket-Control (downloadSocket), a Progressbar (downloadProgress) and a DownloadButton (btnDownload) on this new window.
When the DownloadButton is pressed the method DownloadSqliteDB is called:
[code] Dim downloadFile As FolderItem = SpecialFolder.ApplicationData.Child(“UniFormis”).Child(“uniformis.sqlite”)
When i press the button, there is a uniformis.sqlite-file in my folder, but only 47 bytes large. the “download complete” Message comes immediately and the ProgressBar is at 100 %.
Wheres my fault? This looks to me exactly like the Xojo-Example.
How did you create HTTPSecureSocket on the IDE?. I can only create it by code, but at this mode I don’t know how to use events AuthenticationRequired. Thanks
What’s next is the name of the method that you want to have handle the event. This method has to match the signature of the event it’s handling, and in addition receives a reference to the object that’s raising the event as the first parameter.
i.e. The DownloadComplete event is defined like this:
Sub DownloadComplete(URL as String, HTTPStatus as Integer, Headers as InternetHeaders, File as FolderItem)
So you need to write a method that looks like this:
Sub MyHandler(Sender As HTTPSecureSocket, URL as String, HTTPStatus as Integer, Headers as InternetHeaders, File as FolderItem)
[quote=343871:@Gerardo García]Did you have an example how to use an AddHandler for HTTPSecureSocket, I’m trying to deal with DownloadComplete event of the Handler.
I have several sockets created in code in a array of sockets.
I think that this is the way do deal with AddHandler: