Issuing HTTP(S) Requests

This page describes how to issue HTTP(S) requests from your App Engine
app.

App Engine uses the URL Fetch service to issue outbound HTTP(S) requests.
For details on request size limits and which headers are sent in a URL Fetch
request, see Outbound Requests.

Issuing an HTTP request

To issue an outbound HTTP request, use the
urlfetch.fetch
method. For improved code portability, you can also use the Python standard
libraries urllib, urllib2, or httplib to issue HTTP requests.
When you use these libraries in App Engine, they perform HTTP requests using
App Engine's URL Fetch service. You can also use the third-party requests library as long as you configure it to use URLFetch.

urlfetch

The following snippets demonstrate how to perform a basic HTTP
GET request using urlfetch. First, import
the urlfetch library from the App Engine SDK:

Setting a request timeout

You can adjust the default deadline by using the
urlfetch.set_default_fetch_deadline() function. This function stores the
new default deadline on a thread-local variable, so it must be set for each
request, for example, in a custom middleware.

Issuing an HTTPS request

To issue an HTTPS request, set the validate_certificate parameter
to true when calling the urlfetch.fetch() method.

Setting a request timeout

To set a timeout for your request, set the urlfetch.create_rpc()
method's deadline parameter when you create your RPC object.

Using a callback function

You can define a callback function for your RPC object. The function
will be called when your application calls a method on the
object—such as wait(), checksuccess(), or
get_result()—that causes the object to wait
for the request to complete.

Issuing a request to another App Engine app

When issuing a request to another App Engine app, your App Engine app
must assert its identity by adding the header X-Appengine-Inbound-Appid
to the request.
If you instruct the URL Fetch service to not follow redirects, App Engine
will add this header to requests automatically.

To instruct the URL Fetch service to not follow redirects, set the fetch
method's follow_redirects
parameter to False.

Note: If you are making requests to another App Engine application,
use its appspot.com domain name rather than a custom domain
for your app.

What's next

Learn about the URL Fetch service, such as the headers that are
sent in a URL Fetch request in Outbound Requests.