Announcement

Collapse
No announcement yet.

http() returns true if page doesn't exist?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • http() returns true if page doesn't exist?

    I would have expected the http() call to return false in this code:

    PHP Code:
    var _init false;

    function 
    preMain() {
        
    _init true;
    }

    function 
    main() {
        if(
    _init) {
            var 
    webFile "http://www.esignal.com/this_file_does_not_exist.txt";
            var 
    = new HTTP(webFile);
            var 
    success f.open("rt");
            if(
    success) {
                
    debugPrintln("Found " webFile);
            } else {
                
    debugPrintln("Did not find " webFile);
            }
            
    _init false;
        }

    but apparently it doesn't. Is this the correct behavior?

    if you change the webFile var to "http://www.iamsurethatthiswebsitedoesnotexist.com/this_file_does_not_exist.txt" then it does return false.

    Thanks.
    Standing on the shoulders of giants.

  • #2
    How I use it..

    This is how I've been using the HTTP object with success.

    PHP Code:
    var = new HTTP("http://www.yoursite.com/yourfile.txt");
    v.open("rt");
    if(
    v.open()) {
        while(!
    v.eof()) {
         
    line v.readln();
         if (
    line) {
           
    //  store line data
            
    linecount += 1;
         }
        }
     
    debugPrintln("yourfile.txt Loaded "+linecount);
    } else {
     
    debugPrintln("yourfile.txt NOT Loaded");
    }
    null
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Hello wildfiction,

      Your code is working properly. The reason it returns true is because the url you are using takes you to a "Page Not Found" web page on the www.esignal.com website. It's not the text file you requested but the http object is opening a valid web page.
      Jason K.
      Project Manager
      eSignal - an Interactive Data company

      EFS KnowledgeBase
      JavaScript for EFS Video Series
      EFS Beginner Tutorial Series
      EFS Glossary
      Custom EFS Development Policy

      New User Orientation

      Comment


      • #4
        Originally posted by JasonK
        Hello wildfiction,

        Your code is working properly. The reason it returns true is because the url you are using takes you to a "Page Not Found" web page on the www.esignal.com website. It's not the text file you requested but the http object is opening a valid web page.
        Thanks Jason - that makes sense - I never thought that the page not found "page" would be a valid response - but now it seems very obvious.
        Standing on the shoulders of giants.

        Comment

        Working...
        X