summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-07-21 14:41:22 -0400
committerChris McDonough <chrism@plope.com>2011-07-21 14:41:22 -0400
commit0b0b2065558649c0af65a08e94cd99894889bea3 (patch)
tree3bbd1100ed7e7fe768d7626fc1819f0a03723870
parente7cb93e1c07fb59a523ff8e79732787a3f4ae213 (diff)
downloadpyramid-0b0b2065558649c0af65a08e94cd99894889bea3.tar.gz
pyramid-0b0b2065558649c0af65a08e94cd99894889bea3.tar.bz2
pyramid-0b0b2065558649c0af65a08e94cd99894889bea3.zip
urllib2 example of creating a request suitable for producing a json body
-rw-r--r--docs/narr/webob.rst14
1 files changed, 14 insertions, 0 deletions
diff --git a/docs/narr/webob.rst b/docs/narr/webob.rst
index 6e8c39523..106024db3 100644
--- a/docs/narr/webob.rst
+++ b/docs/narr/webob.rst
@@ -296,6 +296,20 @@ For the above view, printed to the console will be:
{u'a': 1}
+For bonus points, here's a bit of client-side code that will produce a
+request that has a body suitable for reading via ``request.json_body`` using
+Python's ``urllib2`` instead of a Javascript AJAX request:
+
+.. code-block:: python
+
+ import urllib2
+ import json
+
+ json_payload = json.dumps({'a':1})
+ headers = {'Content-Type':'application/json; charset=utf-8'}
+ req = urllib2.Request('http://localhost:6543/', json_payload, headers)
+ resp = urllib2.urlopen(req)
+
More Details
++++++++++++