Issuing HTTP(S) Requests

Python |Java |PHP |Go

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 about how the URL Fetch service is implemented and which headers are sent in a URL Fetch request, see Outbound Requests.

  1. Issuing an HTTP request
  2. Issuing an HTTPS request
    1. Disabling host certificate validation
  3. Issuing a request to another App Engine app

Issuing an HTTP request

To issue an outbound HTTP request, use the http package as usual, but create your client using urlfetch.Client. urlfetch.Client returns an *http.Client that uses urlfetch.Transport, which is an implementation of the http.RoundTripper interface that makes requests using the URL Fetch API.

The following snippet demonstrates how to perform a basic HTTP GET request:

import (
	"fmt"
	"net/http"

	"google.golang.org/appengine"
	"google.golang.org/appengine/urlfetch"
)

func handler(w http.ResponseWriter, r *http.Request) {
	ctx := appengine.NewContext(r)
	client := urlfetch.Client(ctx)
	resp, err := client.Get("https://www.google.com/")
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	fmt.Fprintf(w, "HTTP GET returned status %v", resp.Status)
}

Issuing an HTTPS request

In the Go API, you do not need to explicitly secure your request. The underlying URL Fetch service validates the certificate of the host it is contacting by default, and rejects requests if the certificate does not match.

Disabling host certificate validation

To disable auomatic host certificate validation, you can manually create a Transport and set AllowInvalidServerCertificate to true.

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.

What's next

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

Send feedback about...

App Engine standard environment for Go