Stay organized with collections Save and categorize content based on your preferences.
Region IDThe REGION_ID
is an abbreviated code that Google assigns based on the region you select when you create your app. The code does not correspond to a country or province, even though some region IDs may appear similar to commonly used country and province codes. For apps created after February 2020, REGION_ID.r
is included in App Engine URLs. For existing apps created before this date, the region ID is optional in the URL.
Learn more about region IDs.
This page describes how to issue HTTP(S) requests from your App Engine app.
By default, applications running in the Java 8 runtime use standard Java classes for HTTP(S) requests, such as
java.net.HttpURLConnection
. You send requests as you would for any other Java application. To use the default behavior, you must enable billing for your application or you will get the following exceptions:
java.net.UnknownHostException
java.net.SocketTimeoutException
java.io.IOException
If you use the standard Java network classes, your app will have access to the following features:
url-stream-handler
field in your configuration is not set to urlfetch
. Apps that use Cloud Client Libraries for Java and attempt to use URL Fetch through the URLConnection
wrapper are not supported.
If you have to use URL Fetch in a Java 8 app, add the following line to your appengine-web.xml:
<url-stream-handler>urlfetch</url-stream-handler>
For example:
<xml version="1.0" encoding="utf-8">
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<!-- ... -->
<url-stream-handler>urlfetch</url-stream-handler>
<!-- ... -->
</appengine-web-app>
Note: The metadata server can only be accessed using native Java sockets and the native stream handler and does not support the urlfetch
service. Issue an HTTP request
You issue an outbound HTTP request using
java.net.URLConnection
.
The following snippet demonstrates how to perform a basic HTTP GET
request. The application creates a new URL
object, then calls the object's openStream()
method to retrieve the content at that URL:
For more advanced requests, use java.net.HttpURLConnection
as follows:
URL
object.URLConnection
object by calling your URL
object's openConnection()
method.HttpURLConnection
object by casting your URLConnection
object to the HttpURLConnection
object type.HttpURLConnection
object's request method.The following snippet demonstrates how to use HttpURLConnection
to perform a more advanced request, submitting data from a web form via a PUT
request:
If you are using URL Fetch, you can adjust the default deadline for requests using the appengine.api.urlfetch.defaultDeadline setting in the appengine-web.xml
file.
If you are using URL Fetch, you can set an HTTP header on the outgoing request, by calling your HttpURLConnection
object's setRequestProperty()
method. The following snippet sets the X-MyApp-Version
header to 2.7.3
:
conn.setRequestProperty("X-MyApp-Version", "2.7.3");
Disable redirects Important: To improve the security of your app, it is recommended that you disable redirects.
By default,
HttpURLConnection
follows HTTP redirects.
If you are using URL Fetch, the underlying URL Fetch service follows up to five redirects by default. These redirects could forward sensitive information, such as authorization headers, to the redirected destination. If your app does not require HTTP redirects, it is recommended that you disable the redirects.
To disable this behavior, pass the value false
to your HttpURLConnection
object's setInstanceFollowRedirects()
method:
conn.setInstanceFollowRedirects(false);
If your app uses the underlying urlfetch
package directly instead of java.net
, your app must specify doNotFollowRedirects
.
By default, the underlying URL Fetch service validates the certificate of the host it contacts, and rejects requests if the certificate doesn't match. You don't need to explicitly secure your request.
Disable host certificate validationTo disable automatic host certificate validation in URL Fetch, issue an HTTPS request using the FetchOptions
class in the urlfetch
package and call doNotValidateCertificate()
.
HTTP(S) requests are synchronous by default. To issue an asynchronous request, your application must use URLFetchService
's fetchAsync()
method. This method returns a java.util.concurrent.Future<HTTPResponse>
.
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.
See Disabling redirects for guidance on disabling redirects.
Note: If you are making requests to another App Engine application, use itsREGION_ID.r.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.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["The `REGION_ID` is a Google-assigned code based on the region selected during app creation, included in App Engine URLs for apps created after February 2020, but it does not directly correspond to specific countries or provinces."],["Java 8 runtime applications utilize standard Java classes like `java.net.HttpURLConnection` for HTTP(S) requests, which require billing to be enabled to avoid exceptions."],["While standard Java network classes provide benefits like removing the 32 MB limit and support for HTTP 2.0, avoid URL Fetch if using Serverless VPC Access or Cloud Client Libraries for Java, and ensure the `url-stream-handler` is not set to `urlfetch`."],["You can issue HTTP requests using `java.net.URLConnection`, with more complex requests requiring `java.net.HttpURLConnection` where you will need to create a `URL` object and set request method for the `HttpURLConnection` object."],["To enhance security, disabling HTTP redirects with `conn.setInstanceFollowRedirects(false)` is recommended, and when sending requests to another App Engine app, your app must include the `X-Appengine-Inbound-Appid` header."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4