Monday, November 08, 2010 at 12:01 AM.
system.verbs.apps.netEvents.examples.httpGet
on httpGet (domainName, path, port, adrheader=nil) { <<Do an HTTP get request <<We return the page text, if adrheader is not nil we return the header. <<Mon, Feb 3, 1997 at 4:47:34 AM by DW local (stream, s = "", bytespending, status); local (request); if not (path beginsWith "/") { <<Monday, January 05, 1998 at 9:51:43 PM by PBS <<Add leading slash if it doesn't exist. path = "/" + path}; netevents.launch (); stream = netEvents.openStream (domainName, port); <<Monday, January 05, 1998 at 9:52:15 PM by PBS <<The request now includes the Host: field, <<to work with virtual domain servers. request = "GET " + path + " HTTP/1.0\r\n"; request = request + "User-Agent: Frontier/" + frontier.version () + " (" +sys.os () + ") \r\n"; if port != 80 { request = request + "Host: " + domainname + ":" + port} else { request = request + "Host: " + domainname}; request = request + "\r\n\r\n"; netEvents.writeStream (stream, request); loop { s = s + netEvents.readStream (stream, 10000); status = netEvents.statusStream (stream, @bytespending); case status { "CLOSED"; "INACTIVE" { break}}}; netEvents.closeStream (stream); bundle { <<split the returned text into the header and the page text local (headerkey = "\r\n\r\n", ixheaderkey, ixendkey); ixheaderkey = string.patternMatch (headerkey, s); ixendkey = ixheaderkey + sizeof (headerkey); if adrheader != nil { adrheader^ = string.mid (s, 1, ixendkey - 1)}; s = string.mid (s, ixendkey, sizeof (s) - ixendkey + 1)}; return (s)}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.