March 02, 2011


My son was trying to use to access the Google Docs API and told me he needed the ability to execute HTTP PUT and DELETE, not just GET and POST.

Done. Now supports a "&method=" CGI argument that you can set to PUT or DELETE, and Anthony reports that it's working fine for accessing the API. (Does anybody know of any simple public HTTP servers out there that will echo your request so that it can be easily tested? At most URLs, using these unusual methods will just give you a 405 error.)


Another change is that now supports cross-domain access via XHR (not just jsonp) on browsers that support the Access-Control-Allow-Origin header.

The problem with JSONP is that you can only use the GET method, not POST, so all of your submitted data must fit in a URL string. Some browsers, servers, and proxies may have trouble handling URL strings longer than about 2K, so this means you cannot use JSONP to reliably submit long chunks of data.

The solution is to go back to using traditional XHR techniques, but to tell your browser that cross-origin access is OK using the Access-Control-Allow-Origin header. This header is supported on modern browsers (FF, Chrome, Safari, Opera, and IE8+).

You can write code like the following (jQuery) to use the POST method to interact with jsonlib:

  { url: '' },
  function(m) { output(m); },

The above just uses POST to talk to jsonlib, and asks jsonlib to do a GET, but obviously you can use a POST to ask jsonlib to do a POST or a PUT as well.

Sniffing Character Encodings

The other update is logic for sniffing encodings. Since always returns its contents as JSON unicode strings, it needs to understand how to convert responses from arbitrary other encodings. For text documents, it now uses BeautifulSoup and the chardet library to automatically detect encodings and convert text and html documents to unicode. This behavior can be overridden using the &encoding= CGI argument.

Examples: fetching utf-8 smart quotes and fetching cp-1252 smart quotes.

Non-text documents are treated as iso-8859-1 which is the simplest way use unicode 0-255 codepoints as a way of storing a bytestream (example: fetching a jpeg.)

Posted by David at March 2, 2011 06:52 AM

are you looking for something like

Posted by: helpful person at April 13, 2011 08:43 AM

Thanks for the pointer to postbin. Unfortunately it doesn't allow PUTs, so I can't use it to test those.

Posted by: David at May 15, 2011 09:14 AM
Post a comment

Remember personal info?