HTTPSocket in Web App

Hi all,

I have a Xojo web app that has a page containing a listbox and a canvas. When the user clicks on an item in the listbox, an PNG image related to that list item is supposed to appear in the canvas.

The images come from a PHP website, and I use HTTP GET to retrieve them. They are all mid-size (300-400 KB) images.

Here’s what I’m doing when I ask for the images:

Dim Sock as new HTTPSocket Sock.Get(url, downloadFile, 10) // synchronous download ... code to put the download file in a place where the Canvas Paint event will draw it.
What happens about 40% of the time is that the file I receive is zero bytes. It’s like it’s timing out or closing the connection before receiving it. The HTTP status code is 200, so the remote server thinks everything worked. The other 60% of the time the file is correct, and the image displays in the Canvas.

I know this isn’t a PHP server problem, because I have a standalone Xojo app containing the same HTTPSocket code, and it always downloads the images correctly.

What could be causing this, and what can I do to fix it?

Thanks for your advice!

Well, you have the image url, and you have access to the image.
So why not just assign the url to a WebImageView?

Good question. It’s because the PHP site requires a login cookie.

In other words, it’s not just a simple isolated

If I could figure out how to couple the cookie into a WebImageView, I would definitely go that way.

Is there a way to do that?

Would have to make a test, but technically, your app runs in a web browser, that keeps a cookie for your session, so it should already have the cookie somewhere in the client’s machine if you access the site where the image is located, within the cookies lifespan.

Do you have admin access to the php site where the image is located? If so, you could create a web service inside that site, and use ajax to retrieve the image or its URI , using Rest, soap or plain php http echo.

I can imagine some javascript that gets the cookie, but how would I then associate it (the javascript and/or the cookie) with the web request that WebImageView generates when I change its URL?

And yes, I do have admin access to the PHP site. But we don’t want to open up the images for public viewing, which means I’d need to set up some kind of authenticated service – and again, I’m not sure how a WebImageView would go about authenticating.

I don’t speak web for a living, so I’m probably missing something obvious here.

I don’t think that you can attach the cookie info to the URL of the image view.

Make an authenticated web service that returns the image true URL. It means that your website will connect to the web service via http get, send the authentication token and the image id, and the web service can return the URL in text format. Of course it should be using https in any method you pretend to send or receive some unencrypted data.

Finally, apply the text URL obtained with the web service to the webimageview, and you are set.