put URL - Question

Are you using LiveCode to create server scripts or CGIs?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
richardmac
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 211
Joined: Sun Oct 24, 2010 12:13 am

put URL - Question

Post by richardmac » Thu Feb 10, 2022 6:58 pm

At work I've been using LiveCode to run all kinds of scripts on our web servers, behind the scenes. Today I started playing with LiveCode server - it is installed, and I can do a "Hello world" web page that spits out the current time and date. Hooray!

Question: in a ".lc" web page on my server, can I grab a URL from the web, process it, and spit it back out? In my case, it's an ics file - basically a text file. In regular LiveCode, I can do this:

get URL ("http://site/file.ics")
put it into field "report"

And that works. But in my .lc web page, this does not work:
put URL ("http://site/file.ics") into storeMe
put storeMe

What I'd like to do is grab in ics file off the web, do some parsing, and spit parts of it back out. Is it possible to do? If so, what am I missing? I did a forum search but didn't see anything like this. Any ideas greatly appreciated, as always.

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 133
Joined: Tue Feb 23, 2010 10:53 pm
Location: Saint Louis, Missouri USA

Re: put URL - Question

Post by bobcole » Sun Feb 13, 2022 5:27 am

richardmac:
I have been playing with the server recently so I thought I'd give your question a try.
First, I put an ics file (TestCalendar.ics) on my website's server.
Then I created a simple script in the cgi-bin folder of my website (see below). I called the cgi-bin file ListCalendar.lc.
In the browser's address bar, I entered https://myWebsite/cgi-bin/ListCalendar.lc
The https protocol was important; it didn't work with http.
The most difficult part was making sure the script produced valid html to send back to the browser.
Here is the cgi-bin ListCalendar.lc script that worked for me...

Code: Select all

<html>
<body>
<table>
<?lc
    put URL ("https://myWebsite/TestCalendar.ics") into tStoreMe
    put the number of lines in tStoreMe into tLineCount
    put "<p>The Number of lines in the ics file: " & tLineCount & "</p>"
    put "<p>"
	repeat with j = 1 to tLineCount
		put "Line Number: " & j & " - " & line j of tStoreMe & "<br/>"
	end repeat
	put "</p>"
?>
</table>
</body>
</html>
This script outputs all the lines in the ics file but you can revise the script to ignore/skip whatever lines you don't want.
Let me know if you have any questions,
Bob

richardmac
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 211
Joined: Sun Oct 24, 2010 12:13 am

Re: put URL - Question

Post by richardmac » Mon Feb 14, 2022 6:39 pm

bobcole:
Hmm.
When I use the exact same script you posted (but with the URL to the calendar file set to where my file is located), the number of lines of tStoreMe is 0. It sounds like my installation isn't behaving correctly, based on your test. I'll double-check my ownership/permissions for livecode-community-server. Thanks for the example code - knowing that works elsewhere gives me some direction to follow. :)

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 133
Joined: Tue Feb 23, 2010 10:53 pm
Location: Saint Louis, Missouri USA

Re: put URL - Question

Post by bobcole » Mon Feb 14, 2022 9:13 pm

richardmac:
In my first attempt at creating the URL I used http protocol which caused the same error as you see: zero lines in the storeMe variable.
My website has https enabled so, it turns out, I had to use https in the URL. That change allowed the file to be retrieved correctly.
If you don't have SSL set up, try the http protocol in your URL.
Otherwise, I don't know what else to suggest other than posting your script here.
Bob

Post Reply

Return to “CGIs and the Server”