Exists, there is a, etc.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Exists, there is a, etc.
Hey all,
I am struggling again with something that is most likely very simple…
I want to determine if a file exists at "http://www.wherever.com/guide/test.html".
What am I missing?
Thanks!
I am struggling again with something that is most likely very simple…
I want to determine if a file exists at "http://www.wherever.com/guide/test.html".
What am I missing?
Thanks!
-
- VIP Livecode Opensource Backer
- Posts: 10044
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Exists, there is a, etc.
get "http://www.wherever.com/guide/test.html"
if "error 404" is in the result then ReportNotFoundError
if "error 404" is in the result then ReportNotFoundError
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Exists, there is a, etc.
Thank you Richard… but that is not really an option as the server never returns a 404. It will always have a have a 404 redirect to a "missing" page. While I could conceivably look for a string on that "missing" page to determine if that page was returned, I am not responsible for the content of that page so this may break sometime in the future.
Is there a more reliable way to actually test for whether or not the file I am looking for actually exists?
Is there a more reliable way to actually test for whether or not the file I am looking for actually exists?
-
- VIP Livecode Opensource Backer
- Posts: 10044
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Exists, there is a, etc.
I have a custom 404 page on my site, and the string I posted is part of what the libURL library returns when I call a non-existent page there. This is apparently done by libURL checking the status code in the header of what Apache sends back, rather than relying on the page contents.
What does "the result" return on your site when accessing a non-existent page?
What does "the result" return on your site when accessing a non-existent page?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Exists, there is a, etc.
If I recall how this works, after the get "http://yoururl.com" if you are redirected to a "missing" page the variable 'it' will contain the contents of that page, but 'the result' will still contain the 404 error.
rrBUSS9EE wrote:Thank you Richard… but that is not really an option as the server never returns a 404. It will always have a have a 404 redirect to a "missing" page. While I could conceivably look for a string on that "missing" page to determine if that page was returned, I am not responsible for the content of that page so this may break sometime in the future.
Is there a more reliable way to actually test for whether or not the file I am looking for actually exists?
Re: Exists, there is a, etc.
Have either of you had ANY success in getting error messages returned in the result in iOS?
I always seem to get empty from the SIM even though the error is in the result on the desktop.
This has been driving me crazy trying to debug my scripts in the SIM.
I always seem to get empty from the SIM even though the error is in the result on the desktop.
This has been driving me crazy trying to debug my scripts in the SIM.
Re: Exists, there is a, etc.
Ok… me again. After bashing my head against the wall for the last hour or so, I think I have discovered some really nasty behavior in either LC or iOS. Note this behavior is reproducible in both the Simulator and a device running iOS 5.1.1.
1.) "Get URL <http://pathToNon-ExistantFile>" returns empty in the RESULT, and simply returns empty in "it" as well.
2.) Once you do step one above, this URL is hosed. Even if you now create a file at that URL, both the result and "it" will still return empty.
3.) The only way to get this working again for a valid, existing file at the url mentioned above, is to delete the app and its data, and reinstall on to the device.
This pretty much makes get URL useless. There is obviously a bug in LC with respect to an invalid url not returning an error in the result in iOS as a 404 is returned in the result under Mac OS. But the fact that a referenced url pointing to a non-existent file becomes permanently broken even if after a valid file at that url is created is scary.
Hard to imagine that no one has run into this, but I would be thrilled if someone could provide a work around.
1.) "Get URL <http://pathToNon-ExistantFile>" returns empty in the RESULT, and simply returns empty in "it" as well.
2.) Once you do step one above, this URL is hosed. Even if you now create a file at that URL, both the result and "it" will still return empty.
3.) The only way to get this working again for a valid, existing file at the url mentioned above, is to delete the app and its data, and reinstall on to the device.
This pretty much makes get URL useless. There is obviously a bug in LC with respect to an invalid url not returning an error in the result in iOS as a 404 is returned in the result under Mac OS. But the fact that a referenced url pointing to a non-existent file becomes permanently broken even if after a valid file at that url is created is scary.
Hard to imagine that no one has run into this, but I would be thrilled if someone could provide a work around.
Re: Exists, there is a, etc.
I just tried it and I also get nothing in "it" or in the result. I didn't try creating a file at the location, but since the app will completely shut down every time you close it, you should be able to quit back to the launcher and re-open the app, and it should work again. Does that fail for some reason?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Exists, there is a, etc.
Yes… it does. Once 'get url "abc"' is used with no file at "abc", it is broken. Subsequent calls to 'get url "abc"' returns empty in both it and the result from that point on even if there now is a file at "abc".jacque wrote:Does that fail for some reason?
As I said before, the app needs to be deleted from the device and reinstalled before it will work again.
Re: Exists, there is a, etc.
I just tried it again in the iOS simulator. I do still get empty in both "it" and the result. However, if I then place a file on the server, I can retrieve it successfully without quitting the app.
My test button is simple:
Field 1 contains the URL of a non-existent file. After I place the file on the server, it's returned and put into field 2.
I'd say the lack of any response for a missing file in iOS is a bug, but the second retrieval is working for me.
My test button is simple:
Code: Select all
on mouseUp
put fld 1 into tURL
put "Result:" && the result && url tURL into fld 2
end mouseUp
I'd say the lack of any response for a missing file in iOS is a bug, but the second retrieval is working for me.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Exists, there is a, etc.
Interesting… here is the handler of an example stack I sent support:
As in my original project, once line 3 runs without the file there, that url returns nothing from that point on. I might have thought this could be something on my Mac but this behavior has been confirmed on two iOS devices as well.
Curious what your actual url looks like. Mine was "http://applemountaingolfresort.com/time ... lMenu2.txt"
Code: Select all
on mouseUp
put field "url" into turl
put URL turl into tdata
put the result into tresult
put "the result=""e&tresult"e&CR&CR&"the content=""e&tdata"e into fld urlText
end mouseUp
Curious what your actual url looks like. Mine was "http://applemountaingolfresort.com/time ... lMenu2.txt"
Re: Exists, there is a, etc.
EDIT: Check for trailing space also.
Is there a trailing return? (cr, crlf, etc) in the field after that url? Easiest way to see if this is the problem is change your code to
put line 1 of field "url" into turl
and see if things start working.
I can't test on IOS, but a trailing return causes the behavior you describe for me on android. (could be some other char munging things up I guess)
Nothing is returned, doesn't matter if there is or is not a file if that trailing return is there. Seems like it should error out but it doesn't.
And of course the "urlblahblahblah" in the field doesn't have the quotes around I assume?
EDIT: Check for trailing space also.
Is there a trailing return? (cr, crlf, etc) in the field after that url? Easiest way to see if this is the problem is change your code to
put line 1 of field "url" into turl
and see if things start working.
I can't test on IOS, but a trailing return causes the behavior you describe for me on android. (could be some other char munging things up I guess)
Nothing is returned, doesn't matter if there is or is not a file if that trailing return is there. Seems like it should error out but it doesn't.
And of course the "urlblahblahblah" in the field doesn't have the quotes around I assume?
EDIT: Check for trailing space also.
Re: Exists, there is a, etc.
No trailing spaces, returns, quotes, etc. in the url, as it is hardcoded into the stack (not my example though).
But since Jaque's remarks above, I am looking into this further… using other servers/domains. Although Get URL always returns empty in the result whether or not the file exists, it does return data when the file does exist on some urls and not others. I am still trying to figure out what is different about the ones that work versus the ones that don't.
This is getting fun… stay tuned.
But since Jaque's remarks above, I am looking into this further… using other servers/domains. Although Get URL always returns empty in the result whether or not the file exists, it does return data when the file does exist on some urls and not others. I am still trying to figure out what is different about the ones that work versus the ones that don't.
This is getting fun… stay tuned.
Re: Exists, there is a, etc.
Just noticed this from your posted code jacque..
If this does work, its an extremely cool trick! (if not, am assuming its a typo or copy/paste error)
Code: Select all
on mouseUp
put fld 1 into tURL
put "Result:" && the result && url tURL into fld 2[b] -- won't the result always be empty this way since the url hasn't been hit yet? [/b]
end mouseUp
jacque wrote:I just tried it again in the iOS simulator. I do still get empty in both "it" and the result. However, if I then place a file on the server, I can retrieve it successfully without quitting the app.
My test button is simple:
Field 1 contains the URL of a non-existent file. After I place the file on the server, it's returned and put into field 2.Code: Select all
on mouseUp put fld 1 into tURL put "Result:" && the result && url tURL into fld 2 end mouseUp
I'd say the lack of any response for a missing file in iOS is a bug, but the second retrieval is working for me.
Re: Exists, there is a, etc.
Ok, one more silly question.. When you hard coded the urls, did you copy them from somewhere then paste them into the script? If so, you might find one that reliably has the issue you are dealing with, empty it and hand type the url in again and see if the problem magically goes away. If not, on to the next theory. If so, sounds like something odd was copied along with the url. (I've had similar problems before, copy a script from a web site, paste it in, strange things occur, type it in by hand, works like a charm)
Really wish I could test on IOS *sigh* As mentioned though, android does do the same thing when there is something odd about the URL.
Another thing you might do is run the URL through a small script like so:
put tUrl into tempUrl
set the itemdelimiter to "/"
put urlencode(the last item of tempUrl) into the last item of tempUrl
answer information "encodedUrl: " & tempUrl --if there is any freakishness hopefully urlencode will make it show up
Could also try the script on your tUrl directly and use it with your get and see if the result && it will actually return something using the encoded url.
Really wish I could test on IOS *sigh* As mentioned though, android does do the same thing when there is something odd about the URL.
Another thing you might do is run the URL through a small script like so:
put tUrl into tempUrl
set the itemdelimiter to "/"
put urlencode(the last item of tempUrl) into the last item of tempUrl
answer information "encodedUrl: " & tempUrl --if there is any freakishness hopefully urlencode will make it show up
Could also try the script on your tUrl directly and use it with your get and see if the result && it will actually return something using the encoded url.
rrBUSS9EE wrote:No trailing spaces, returns, quotes, etc. in the url, as it is hardcoded into the stack (not my example though).
But since Jaque's remarks above, I am looking into this further… using other servers/domains. Although Get URL always returns empty in the result whether or not the file exists, it does return data when the file does exist on some urls and not others. I am still trying to figure out what is different about the ones that work versus the ones that don't.
This is getting fun… stay tuned.