Skip to page content Skip to main navigation
English | Site Directory

e.g. "templates" or "datastore"

# The fetch Function

The `google.appengine.api.urlfetch` package provides the following function:

fetch(url, payload=None, method=GET, headers={}, allow_truncated=False, follow_redirects=True)

  Fetches a document at the URL given in url, and returns an object containing the details of the response. See Response Objects for details about the return value.

  Arguments:

  url
    An `http` or `https` URL. If the URL is invalid, a InvalidURLError is raised.
  payload
    Body content for a `POST` or `PUT` request.
  method
    The HTTP method to use for the request. Acceptable values include `GET`, `POST`, `HEAD`, `PUT`, and `DELETE`. These values are constants provided by the package.
  headers
    The set of HTTP headers to include with the request, as a mapping of names and values. For security reasons, some HTTP headers cannot be modified by the application. See Disallowed HTTP Headers.
  allow_truncated
    If `False` and the response data exceeds the maximum allowed response size, a ResponseTooLargeError exception is raised. If `True`, no exception is raised, and the response's `content` is truncated to the maximum size, and the response object's `content_was_truncated` attribute is set to `True`.
  follow_redirects

    If `True`, responses that are HTTP redirects are followed, up to 5 consecutive redirects. The response data is from the final location, as if the data were for the requested location. If `False`, redirects are not followed, and a redirect response is returned directly to the application, including the header information that describes the redirect.

    Warning: Cookies are not handled upon redirection. If cookie handling is needed, set follow_redirects to `False` and handle both cookies and redirects manually.

  The fetch action is synchronous. `fetch()` will not return until the server responds. A slow remote server may cause your application's own request to time out.

  Note: URL fetching cannot authenticate the server of an `https` request because there is no certificate trust chain. The proxy accepts all certificates, including self-signed certificates.

## Disallowed HTTP Headers

For security reasons, the following HTTP headers for outbound HTTP requests cannot be modified by the application.

- `Content-Length`
- `Host`
- `Referer`
- `User-Agent`
- `Vary`
- `Via`
- `X-Forwarded-For`