Monday, November 08, 2010 at 12:06 AM.


on httpPost (url, adrparamtable=nil, username="", password="", adrcode=nil) {
		<<9/13/09; 9:37:38 AM by DW
			<<New optional parameter returns the HTTP result code. Follow redirects. 
		<<7/15/09; 8:35:03 AM by DW
			<<Created. A super-simple interface to HTTP POST. It can get richer with optional parameters, over time, as necessary.
	local (body, urllist, type = "application/x-www-form-urlencoded");
	bundle { //get body
		body = "";
		if adrparamtable != nil {
			local (adr);
			for adr in adrparamtable {
				local (s = string.urlencode (nameof (adr^)) + "=" + string.urlencode (adr^));
				if sizeof (body) == 0 {
					body = s}
				else {
					body = body + "&" + s}}}};
	bundle { //get urllist
		try {
			urllist = string.urlsplit (url)}
		else {
			urllist = string.urlsplit (url + "/")}};
	local (s = tcp.httpclient ("POST", server:urllist [2], path:urllist [3], datatype:type, data:body, ctFollowRedirects:5, debug:false, username:username, password:password));
	if adrcode != nil {
		adrcode^ = tcp.httpGetStatusCode (s)};
	return (string.httpResultSplit (s))}
<<bundle //test code
	<<local (url = "", params)
	<<new (tabletype, @params)
	<<params.url = ""
	<<dialog.alert (httpPost (url, @params))

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.