Making a web/ajax call

Discussion in 'Server and Client Scripting' started by TheUnknownCylon, May 30, 2010.

  1. TheUnknownCylon

    TheUnknownCylon New Member

    Joined:
    May 30, 2010
    Messages:
    3
    Likes Received:
    0
    Hi folks,

    I am the leader of a dutch pokemon community. A member of our community has set up a Pokemon online server. I want to call a HTTP-page (ajax red, url is fine) when a user connects the server. With those scripts, we will be able to show the online users on our website.

    The question is, how can I call a webpage uri with qtscript (the result don't have to be parsed or read).

    So I want to do something like this:
    * Server starts
    * User connects
    * -> Server calls http://mysite.nl/userconnected.php?username=Pietje
    * User disconnects
    * -> Server calls http://mysite.nl/userdisconnected.php?username=Pietje

    How can I arrange this with qtscript? (the external webpage call)
    I've noticed that XMLHttpRequest() does not work.

    Thx in advance!

    Edit, it seems that qurl and qdownloader can't be used.
    Importer.loadQtBinding( "qt.core" ); Importer.loadQtBinding( "qt.xml" ); both fail.
     
    Last edited: May 30, 2010
  2. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
  3. Steve

    Steve Active Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    491
    Likes Received:
    45
    I think he wants it to open client side, coyotte.
     
  4. TheUnknownCylon

    TheUnknownCylon New Member

    Joined:
    May 30, 2010
    Messages:
    3
    Likes Received:
    0
    No, it's fine when the server calls the AJAX.
    Using sys() is a very dangerous thing, it can be exploited and then the system can be hacked in any way.
    I personally think it's not a useless function, it can be used for many many purposes.

    Is it ok if I write a patch for it? I'll hand it in to you, so you can apply this patch on your server software?
     
  5. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Of course it's ok and i'll be glad.

    And using sys.system() is dangerous only if people have direct access to the scripts, but you know your server better than me.
     
  6. TheUnknownCylon

    TheUnknownCylon New Member

    Joined:
    May 30, 2010
    Messages:
    3
    Likes Received:
    0
    Webcall patch

    I wrote the webCall function. The patch is uploaded @SourceForge (https://sourceforge.net/tracker/?func=detail&aid=3009854&group_id=266365&atid=1133861).

    It supports non-encrypted non-authorized http-calls
    * GET
    * POST

    Code (text):
    1. webCall( String uri, String expr, [ Array post [ key=>value ] ].
    expr will be evaluated when the http request is handled (the server will not block!)
    In expr one should use resp to get the response.

    Example 1:
    Code (text):
    1. sys.webCall('http://www.mysite.com/getwelcomemsgtxt', 'print( resp )');
    It will download a welcome messaged from http://www.mysite.com/getwelcomemsg.txt and print it on screen.

    Example 2:
    Code (text):
    1. var x = Array();
    2. x['uname'] = 'Pietje';
    3. x['foo'] = 'bar';
    4. sys.webCall('http://www.mysite.com/usergoesonline', 'myfunc( resp )', x);
    This will send x to the uri as a HTML-form result. When the response is returned, a function myfunc will be called with the server response.
     
  7. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    168
    Ok, thanks a lot, it will be added.