Sending long JSON objects (polygon geometry, table rows) in POST request to Geoprocessing Service?
It's fairly easy with urllib2
. Say you've got a gigantic url like this:
http://myserver/path/to/a/thing?json1={"data":[1,2,3,4,5]}&json2={"data":[1,2,3,4,5]}&json3={"data":[1,2,3,4,5]}
All you need to do is take the query (everything after the ?
) and jam it in the data argument to urlopen
.
import urllib2
import urlparse
# GET
return_data = urllib2.urlopen(url).read()
# POST
url_parts = urlparse.urlsplit(url)
base_url = urlparse.urlunsplit(url_parts[:3] + (None, None))
return_data = urllib2.urlopen(base_url, url_parts.query).read()
Then there's Requests
, which is not in the standard library but it is really, really nice and intuitive to use.