[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-19 (世界標準時間)。"],[[["\u003cp\u003eApp Engine applications can issue HTTP and HTTPS requests using either the \u003ccode\u003ejava.net.URLConnection\u003c/code\u003e class from the Java standard library or the App Engine URL Fetch API.\u003c/p\u003e\n"],["\u003cp\u003eRequests can be made using various HTTP methods such as \u003ccode\u003eGET\u003c/code\u003e, \u003ccode\u003ePOST\u003c/code\u003e, \u003ccode\u003ePUT\u003c/code\u003e, \u003ccode\u003eHEAD\u003c/code\u003e, \u003ccode\u003eDELETE\u003c/code\u003e, and \u003ccode\u003ePATCH\u003c/code\u003e, and the target URL's protocol determines whether HTTP or HTTPS is used.\u003c/p\u003e\n"],["\u003cp\u003eThe URL Fetch service uses a proxy, allows for setting timeouts with a default of 10 seconds (up to 60 seconds max), and supports both synchronous and asynchronous request handling.\u003c/p\u003e\n"],["\u003cp\u003eCertain HTTP headers, like \u003ccode\u003eContent-Length\u003c/code\u003e and \u003ccode\u003eHost\u003c/code\u003e, cannot be modified by the application, and some, such as \u003ccode\u003eUser-Agent\u003c/code\u003e and \u003ccode\u003eX-Appengine-Inbound-Appid\u003c/code\u003e, are automatically managed or appended by App Engine for identification purposes.\u003c/p\u003e\n"],["\u003cp\u003eThe URL Fetch service has limitations on request size (10MB), request header size (16KB), and response size (32MB), but using the \u003ccode\u003ejava.net.URLConnection\u003c/code\u003e does not have those limitations.\u003c/p\u003e\n"]]],[],null,["# URL Fetch for legacy bundled services\n\nThis page describes how App Engine applications\n\nissue HTTP and HTTPS requests and receive responses.\nTo see code samples demonstrating how to issue HTTP and HTTPS requests from your\nApp Engine application, see\n[Issuing HTTP(S) Requests](/appengine/docs/legacy/standard/java/issue-requests).\n\n\nRequests\n--------\n\nIn the App Engine Java 8 runtime, you can use the [`java.net.URLConnection`](https://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html) abstract class, and related classes from the Java standard library, to make HTTP and HTTPS connections from your Java application.\n\n\u003cbr /\u003e\n\nAlternatively, you can also use the App Engine\nURL Fetch API, which provides an implementation of the methods defined in\n`URLConnection` by using the URL Fetch API. For information on using the native\nJava classes versus the URL Fetch API, see\n[Advantages to using standard Java calls and not URL Fetch in Java 8](/appengine/docs/legacy/standard/java/issue-requests#advantages_to_using_standard_java_calls_and_not_url_fetch_in_java_8).\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| java-gen2\n|\n| /services/access). If you are updating to the App Engine Java 11/17 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/java-differences) to learn about your migration options for legacy bundled services.\n\n### Request protocols\n\nAn application can fetch a URL using either HTTP or HTTPS. The protocol that\nshould be used is inferred by looking at the protocol in the target URL.\n\nThe URL to be fetched can use any port number in the following\nranges:\n\n- `80`-`90`\n- `440`-`450`\n- `1024`-`65535`.\n\nIf the port is not mentioned in the URL, the port is implied by the\nprotocol. HTTP requests occur on port `80`, and HTTPS requests occur\non port `443`.\n\n### Request methods\n\nIf you issue requests through the standard Java [`java.net.URLConnection`](https://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html) class, you can use any supported HTTP method.\n\nIf you issue requests through the URL Fetch service, you can use any of the\nfollowing HTTP methods:\n\n- `GET`\n- `POST`\n- `PUT`\n- `HEAD`\n- `DELETE`\n- `PATCH`\n\nA request can include HTTP headers and, for `POST`, `PUT`, and `PATCH`\nrequests, a payload.\n\n### Request proxying\n\nNote that the URL Fetch service uses an HTTP/1.1 compliant proxy to fetch the result.\n\nTo prevent an application from causing an endless recursion of requests, a\nrequest handler is not allowed to fetch its own URL. It is still\npossible to cause an endless recursion with other means, so\nexercise caution if your application can be made to fetch requests for\nURLs supplied by the user.\n\n### Request headers\n\nYour application can set HTTP headers for the outgoing request.\n\nWhen sending an HTTP `POST` request, if a `Content-Type` header is\nnot set explicitly, the header is set to `x-www-form-urlencoded`.\nThis is the content type used by web forms.\n\nFor security reasons, the following headers cannot be modified\nby the application:\n\n- `Content-Length`\n- `Host`\n- `Vary`\n- `Via`\n- `X-Appengine-Inbound-Appid`\n- `X-Forwarded-For`\n- `X-ProxyUser-IP`\n\nThese headers are set to accurate values by App Engine as\nappropriate. For example, App Engine calculates the\n`Content-Length` header from the request data and adds it to\nthe request prior to sending.\n\nThe following headers indicate the application ID of the requesting app:\n\n- `User-Agent`. This header can be modified, but App Engine will append an identifier string to allow servers to identify App Engine requests. The appended string has the format `\"AppEngine-Google; (+http://code.google.com/appengine; appid: APPID)\"`, where `APPID` is your app's identifier.\n- `X-Appengine-Inbound-Appid`. This header cannot be modified, and is added automatically if the request is sent via the URL Fetch service when the follow redirects parameter is set to `False`.\n\n### Request timeouts\n\nYou can set a deadline, or timeout, for a request. By default, the\ntimeout for a request is 10 seconds.\n\nThe maximum deadline is 60 seconds for HTTP(S) requests and 60 seconds\nfor Task Queue and cron job requests.\n\n\nWhen using the `URLConnection` abstract class with URL Fetch, the service uses the\nconnection timeout (`setConnectTimeout()`) plus the read timeout\n(`setReadTimeout()`) as the deadline.\n\n\nYou can send synchronous requests and asynchronous requests. The following\nbehavior applies to the URL Fetch API:\n\n- *Synchronous requests*: The fetch call waits until the remote host returns a result, and then returns control to the application. If the maximum wait time for the fetch call is exceeded, the call raises an exception.\n- *Asynchronous requests*: The URL Fetch service starts the request, then returns immediately with an object. The application can perform other tasks while the URL is being fetched. When the application needs the results, it calls a method on the object, which waits for the request to finish if necessary, then returns the result. If any URL Fetch requests are pending when the request handler exits, the application server waits for all remaining requests to either return or reach their deadline before returning a response to the user.\n\nSecure connections and HTTPS\n----------------------------\n\nYour application can fetch a URL securely by using HTTPS to connect to\nsecure servers. Request and response data are transmitted over the\nnetwork in encrypted form.\n\nBy default, the URL Fetch proxy validates the host it contacts. This behavior\nallows the API to detect man-in-the-middle attacks\nbetween App Engine and the remote host when using HTTPS.\n\nResponses\n---------\n\nIf you use the URL Fetch API, note that the URL Fetch service returns all\nresponse data, including the response, code, headers, and body.\n\nBy default, if the URL Fetch service receives a response with a\nredirect code, the service will follow the redirect. The service will\nfollow up to five redirect responses, then return the final resource.\n\nYou can\n[instruct the URL Fetch service to not follow redirects](/appengine/docs/legacy/standard/java/issue-requests#issuing_a_request_to_another_app_engine_app)\nand instead return a redirect response to the application.\n\n\n| **Note:** The URL Fetch API imposes response\n| size limits. If the incoming\n| response exceeds the maximum response size\n| limit, the URL Fetch service raises an exception. See the\n| [Quotas and limits](#quotas_and_limits_for_url_fetch) section for details.\n|\n| You can instruct the URL Fetch API to truncate the response instead of\n| raising an exception.\n\nUsing URL Fetch on the development server\n-----------------------------------------\n\nWhen your application is running on the App Engine development server on your\ncomputer, calls to the URL Fetch service are handled locally. The\ndevelopment server fetches URLs by contacting remote hosts directly\nfrom your computer, using whatever network configuration your computer\nis using to access the Internet.\n\nWhen testing the features of your application that fetch URLs, make sure\nthat your computer can access the remote hosts.\n\nQuotas and limits for URL Fetch\n-------------------------------\n\nFor the Java runtime, you can use the standard Java [`java.net.URLConnection`](https://docs.oracle.com/javase/7/docs/api/java/net/URLConnection.html) API, instead of URLFetch, where these quota and limit considerations do not apply.\n\nFor information about URL Fetch service quotas, see\n[Quotas](/appengine/docs/quotas#UrlFetch). To see the current quota usage of\nyour application, go to the Quota Details page in the\nGoogle Cloud console.\n\n[Go to the Quota Details page](https://console.cloud.google.com/appengine/quotadetails)\n\nIn addition, the following limits apply to the use of the\nURL Fetch service:\n\nWhat's next\n-----------\n\nRun code samples and get guidance on how to issue requests from your\napplication in [Issuing HTTP(S) Requests](/appengine/docs/legacy/standard/java/issue-requests)."]]