Two questions about urlfetch

8 views
Skip to first unread message

r.

unread,
Apr 8, 2008, 3:41:38 PM4/8/08
to Google App Engine
1. I cannot find in the documentation how to provide the payload
argument for a post request using urlfetch.

2. When the response has a 302 status, is it possible to "follow" the
redirection ?

Anyone for a sample of use ?

Thanks,

r.

Shalabh Chaturvedi

unread,
Apr 8, 2008, 4:12:56 PM4/8/08
to Google App Engine
On Apr 8, 12:41 pm, "r." <raphael.mar...@gmail.com> wrote:
> 1. I cannot find in the documentation how to provide the payload
> argument for a post request using urlfetch.

I think you can use the payload parameter to the fetch() function. See
http://code.google.com/appengine/docs/urlfetch/fetchfunction.html

> 2. When the response has a 302 status, is it possible to "follow" the
> redirection ?

You should be able to do this yourself - if the status_code is 302,
the 'location' header in the response usually contains the new URL.

r.

unread,
Apr 9, 2008, 2:43:56 AM4/9/08
to Google App Engine


shalabh wrote:
> On Apr 8, 12:41 pm, "r." <raphael.mar...@gmail.com> wrote:
> > 1. I cannot find in the documentation how to provide the payload
> > argument for a post request using urlfetch.
>
> I think you can use the payload parameter to the fetch() function. See
> http://code.google.com/appengine/docs/urlfetch/fetchfunction.html

My question was not properyl written: I am using a post, what is the
payload parameter supposed to be ? a urlencode ? a json string ? I can
only see that it requests a string as parameter.

> > 2. When the response has a 302 status, is it possible to "follow" the
> > redirection ?
>
> You should be able to do this yourself - if the status_code is 302,
> the 'location' header in the response usually contains the new URL.

nope, there's nothing in the header.

r.

unread,
Apr 9, 2008, 5:47:46 AM4/9/08
to Google App Engine

The payload has to be a urlencode string and it seems required to
provide a headers dict to urlfetch when doing a post request such as:

data = urlencode(...)
headers = dict('Content-type':'application/x-www-form-
urlencoded'})
response = urlfetch.fetch(url, payload=data, method=urlfetch.POST,
headers=headers)
if response.status_code == 302:
url = BASE_URL + response.headers['location']
response = urlfetch.fetch(url)

HTH

r.

r.

unread,
Apr 9, 2008, 5:47:55 AM4/9/08
to Google App Engine
Reply all
Reply to author
Forward
0 new messages