All pastes #154104 Raw Edit

Mine

public text v1 · immutable
#154104 ·published 2006-08-30 04:19 UTC
rendered paste body
function test_get() {
	// This is an example on how to create an XPCOM in JS.
	//var file = Components.classes["@mozilla.org/file/local;1"].createInstance();
	// After the instance is created you use getService();
	//var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
	// This is a "short cut".
	//var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);

	// This will add a download th
	//nsIDownload addDownload ( PRInt16 downloadType , nsIURI source , nsIURI target , AString displayName , AString iconURL , nsIMIMEInfo MIMEInfo , PRTime startTime , nsILocalFile tempFile , nsICancelable cancelable )
	var nsIFileProtocolHandler = Components.classes["@mozilla.org/network/protocol;1?name=file"].createInstance(Components.interfaces.nsIFileProtocolHandler);
	
	var nsIFile = nsIFileProtocolHandler.getFileFromURLSpec("file://home/erm/tmp.pdf");
	
	var nsIDownloadObserver = {  
		onDownloadComplete: function(nsIDownloader, nsresult, nsIFile) {
			dump( "\nDownloadComplete" );
		}
	};
	
	var nsIDownloader =  
	Components.classes["@mozilla.org/network/downloader;1"].createInstance();  
	nsIDownloader.QueryInterface(Components.interfaces.nsIDownloader);  
	nsIDownloader.init( nsIDownloadObserver, nsIFile );  

	var nsIIOService = Components.classes["@mozilla.org/network/io-service;1"].
            getService(Components.interfaces.nsIIOService);
	
	nsIHttpChannel = nsIIOService.newChannel("http://the-erm.com/591-096811-007A.pdf", "", null);
	nsIHttpChannel.QueryInterface(Components.interfaces.nsIHttpChannel);  
	nsIHttpChannel.requestMethod = "GET"; // Optional as is default  
	nsIHttpChannel.asyncOpen( nsIDownloader, nsIFile );

}