Help on HTTPSocket

Xojo 2015.2.2
OS X Yosemite 10.10.3

I am currently working on an old program that has a check inside of the version and, if an older version, allows for the download of the latest version.

I keep my version info in a .txt file in one of my public dropbox folders.

My original code looks like this:

dim updateversion as string dim h as new httpsocket h.Yield = False updateversion = h.get(VersionURL, 5) // get the lines
VersionURL is the web address and actual file name (like “https:\\…\version.txt”)

This returned the text inside Version.txt (it just holds a single line like “1.18.1”.

Now when I run the app what is returned is an html file, none of which contains any of the Version.txt text!

Can someone help me with getting the text?

Thank you.

Simon.

dim s, updateversion as String
dim url as string = "http://www.website.com/text.txt"
dim h as new HTTPSocket
s = (h.get (url, 100))
updateversion = DefineEncoding(NthField(s, EndOfLine,1), Encodings.UTF8)

[quote=195118:@Axel Schneider] dim s, updateversion as String dim url as string = "http://www.website.com/text.txt" dim h as new HTTPSocket s = (h.get (url, 100)) updateversion = DefineEncoding(NthField(s, EndOfLine,1), Encodings.UTF8) [/quote]
I just get the first line ("").

This is really stumping me.

If I put the full web address that is in url in Safri I get a blank screen with the version text displayed!

So Safari is going to the right place and opening the version.txt file to display its contents.

Can you test this

I have uploaded a text file that contains only ‘1.7.5’ and it works for me in OSX 10.4 and Xojo 2015R1

Will do.

Yes, that works.

Can you try with my url:
https://dl.dropboxusercontent.com/u/10747116/InternetUpdates/sbBank/version.txt

I am beginning to feel that this is a dropbox issue and not a ‘normal’ issue!

you must use securesocket

  dim s, updateversion as String
  dim url as string = "https://dl.dropboxusercontent.com/u/10747116/InternetUpdates/sbBank/version.txt"
  dim h as new HTTPSecureSocket
  h.ConnectionType = SSLSocket.TLSv1
  s = (h.get (url, 100))
  updateversion = DefineEncoding(NthField(s, EndOfLine,1), Encodings.UTF8)
  Label1.Text = updateversion

Yay!

Thank you, Axel, that is great.

Can you take a minute or two to explain to me why? And why the old code used to work and now doesn’t?

may be because the URL begins with ‘https’

Ok. I now have the following code:

dim h as new HTTPSecureSocket h.ConnectionType = SSLSocket.TLSv1 AddHandler h.DownloadComplete, AddressOf DLComplete AddHandler h.ReceiveProgress, AddressOf Progress h.get(NewVersionURL, DownloadFile) RemoveHandler h.DownloadComplete, AddressOf DLComplete RemoveHandler h.ReceiveProgress, AddressOf Progress
I am not getting anything in my two methods (DLComplete or Progress).

Can you see what I am doing wrong?

I don’t know

I’ve updated the example

to show how I download a file (change the link in the download button to your link)

You’re removing the handlers before the transfer completes.

h.get(NewVersionURL, DownloadFile)

This syntax performs an asynchronous GET request; it returns before the transfer has completed. The transfer runs in the background and eventually raises the DownloadComplete event. Meanwhile the rest of your code runs normally, including the RemoveHandler lines.

Use your original code but with an HTTPSecureSocket: it completes the transfer before returning:

updateversion = h.get(VersionURL, 5) // get the lines

[quote=195205:@Andrew Lambert]You’re removing the handlers before the transfer completes.

h.get(NewVersionURL, DownloadFile)

This syntax performs an asynchronous GET request; it returns before the transfer has completed. The transfer runs in the background and eventually raises the DownloadComplete event. Meanwhile the rest of your code runs normally, including the RemoveHandler lines.

Use your original code but with an HTTPSecureSocket: it completes the transfer before returning:

updateversion = h.get(VersionURL, 5) // get the lines

It is still not going into the routines at all.

I am using this code now:

[code] dim h as new HTTPSecureSocket
h.ConnectionType = SSLSocket.TLSv1
h.Yield = False
AddHandler h.DownloadComplete, AddressOf DLComplete
AddHandler h.ReceiveProgress, AddressOf Progress

dim dlok As Boolean = h.get(NewVersionURL, DownloadFile, 10)

RemoveHandler h.DownloadComplete, AddressOf DLComplete
RemoveHandler h.ReceiveProgress, AddressOf Progress
[/code]
The program never gets to DLComplete or Process.

It does, however, complete the download.

[quote=195202:@Axel Schneider]I don’t know

I’ve updated the example

to show how I download a file (change the link in the download button to your link)[/quote]
I will have a go with this one now.

Thank you, Axel.

Axel

Thank you. That worked perfectly and gives me what I want.

Simon.

It shouldn’t.

Just so you’re clear, HTTPSocket.Get can run in two distinct modes, async or sync, depending on the parameters you pass to it. In Asynchronous mode, Get returns immediately, and some time later, the events fire. In Synchronous mode, Get hangs until the transfer is complete and no events fire at all.

[quote=195228:@Tim Hare]It shouldn’t.

Just so you’re clear, HTTPSocket.Get can run in two distinct modes, async or sync, depending on the parameters you pass to it. In Asynchronous mode, Get returns immediately, and some time later, the events fire. In Synchronous mode, Get hangs until the transfer is complete and no events fire at all.[/quote]
Tim

Thank you. I have had another problem with AddHandler recently but I’ll post that as a separate thread.

I understand the issues now with HTTPSecureSocket and am very happy with the result.

Simon.