The problem is that you do not have an event loop to drive HTTP. There are two options, either you have to create an event loop or you should set the nsIHTTPChannel::openInputStreamHasEventQueue attribute to FALSE. This will cause anotherthread to be spawned for internal event processing. Beware, however, thatHTTP is not thread safe, so this solution will not work for multiple overlappeddownloads. Make sure that there are no other threads trying to access HTTP. Eventually, this poor-man's synchronous implementation will be replacedby a true synchronous implementation (single threaded, no event queue requirement,etc.).
Darin
Eric Plaster wrote:
[EMAIL PROTECTED]">
I'm trying to pull down a web page and I'm having some problems... I'm using the code below (loadWebPage()), and it never says that there is data available. Am I doing this all wrong? Keep in mind this is just to see if I can pull a page, I haven't cleaned it up or do anything other then just dump the contents...-thanks for any help
-ericBTW, this is code that I ripped out of postings n.p.m.netlib and nsXmlRpcClient and a few others. So if it looks a little familiar... ;)
/* Get a pointer to a service indicated by the ContractID, with given interface */
function getService(contractId, intf) {
return Components.classes[contractId].getService(Components.interfaces[intf]);
}function loadWebPage() {
// **** Set this to a small, valid file
var url = "http://www.talkware.net/";// convert to nsIURL interface.
var url_ob = Components.classes["@mozilla.org/network/standard-url;1"]
.createInstance()
.QueryInterface(Components.interfaces.nsIURL);
url_ob.spec = url;// Now open the URL.
var ioService = getService('@mozilla.org/network/io-service;1',
'nsIIOService');
var atomService = getService('@mozilla.org/atom-service;1',
'nsIAtomService');var channel = ioService.newChannelFromURI(url_ob)
.QueryInterface(Components.interfaces.nsIHTTPChannel);channel.SetRequestMethod(atomService.getAtom('GET'));
channel.SetRequestHeader(atomService.getAtom('content-type'), 'text/html');var inputStream = channel.openInputStream();
// make the input stream scriptable.
var sinputStream =
Components.classes["@mozilla.org/scriptableinputstream;1"]
.createInstance()
.QueryInterface(Components.interfaces.nsIScriptableInputStream);
sinputStream.init(inputStream);while(!sinputStream.available()) {
dump("waiting....\n");
}
while(sinputStream.available()) {
dump("Read '" + sinputStream.read(1024) + "'\n");
}// close everything I know how!
inputStream.close();
sinputStream.close();
}
--
----
Eric Plaster Universal Talkware Corp
Senior Software Engineer (612)843-6711
[EMAIL PROTECTED] http://www.talkware.net