Shoutbox

Fetch Webpage without Freezing WLM [SOLVED] - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Fetch Webpage without Freezing WLM [SOLVED] (/showthread.php?tid=91309)

Fetch Webpage without Freezing WLM [SOLVED] by prashker on 07-02-2009 at 07:55 PM

js code:
    var temp = WinHttpReq.Open("GET", "http://sonicsam.net/xboxXXX.php?"+date.getTime(), false);
    WinHttpReq.Send();
    strResult = WinHttpReq.ResponseText;

WLM freezes until the page has completely loaded (even in the browser, because of the functions I use in the PHP code, it takes a few seconds).

How can I do this in a way that WLM will not freeze.

I had an idea, maybe download the page via wget, then load the file locally, and read that. However this script runs every 5 minutes and I don't want a wget command prompt window coming up every 5 minutes (and I would have to add a timer, because wget wouldn't be able to tell the script that it is done downloading the page, proceed to read it) But I guess there is code to check that 'while file doesn't exist, check if file exists'
RE: Fetch Webpage without Freezing WLM by Mnjul on 07-02-2009 at 08:00 PM

You can make the operation asynchronous by passing true as the third parameter in the Open method.

On a side note, why don't you use XMLHttpRequest? It has ResponseText too :p


RE: Fetch Webpage without Freezing WLM by prashker on 07-02-2009 at 08:14 PM

quote:
Originally posted by Mnjul
You can make the operation asynchronous by passing true as the third parameter in the Open method.

Error: The data necessary to complete this operation is not yet available.
(code: -2147483638)
RE: Fetch Webpage without Freezing WLM by matty on 07-02-2009 at 08:19 PM

js code:
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open('GET', 'http://sonicsam.net/xboxXXX.php?'+date.getTime(), true);

    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            Debug.Trace(xmlhttp.responseText);
        }
    }
   
    xmlhttp.send('');

RE: Fetch Webpage without Freezing WLM by Mnjul on 07-02-2009 at 08:20 PM

Indeed, you need to call Waitforresponse() which wait until the data is ready :p ...and that would still block your program.

I now see using WinHttpRequest maybe not suitable for single-thread, so why not XMLHttpRequest? (A)


RE: Fetch Webpage without Freezing WLM by mynetx on 07-02-2009 at 08:21 PM

jscript code:
var objAjax = new ActiveXObject("Microsoft.XMLHTTP");
var strUrl = "http://sonicsam.net/xboxXXX.php?" + new Date().getTime();
>>>objAjax.open("GET", strUrl, true); // async<<<
objAjax.onreadystatechange = function() {
    if(objAjax.readystate != 4)
        return;
    var intStatus = 12027;
    try {
        intStatus = objAjax.status;
    }
    catch(e) { }
    if(intStatus != 200) {
        Debug.Trace("Web connection error " + intStatus);
        return;
    }
    Debug.Trace(objAjax.responseText);
};
objAjax.send();

RE: Fetch Webpage without Freezing WLM by prashker on 07-02-2009 at 08:47 PM

matty's code worked, thanks :banana:

quote:
Originally posted by Mnjul
I now see using WinHttpRequest maybe not suitable for single-thread, so why not XMLHttpRequest?
psh :D