Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
ID de región
REGION_ID es un código abreviado que Google asigna en función de la región que eliges cuando creas la app. El código no corresponde a un país ni a una provincia, aunque algunos ID de región puedan parecer similares a los códigos de país y provincia que se suelen usar. En el caso de las apps creadas después de febrero de 2020, REGION_ID.r se incluye en las URL de App Engine. En el caso de las apps existentes creadas antes de esta fecha, el ID de región es opcional en la URL.
Esta página describe cómo emitir solicitudes HTTP(S) desde tu aplicación de App Engine.
App Engine usa el servicio de recuperación de URL para emitir solicitudes HTTP(S) salientes.
Para obtener más información sobre cuáles son los límites de tamaño de las solicitudes y qué encabezados se envían en una solicitud de recuperación de URL, consulta Solicitudes salientes.
Emite una solicitud HTTP
El lenguaje PHP proporciona varias funciones para hacer solicitudes HTTP remotas.
Estas se implementan de distintas formas en Google App Engine y están sujetas a distintas cuotas y costos:
Controladores de transmisión: Los controladores de transmisión nativos PHP http:// y https:// están configurados para usar el servicio de recuperación de URL de App Engine a fin de realizar solicitudes HTTP. Muchas funciones de PHP como file_get_contents() usan controladores de transmisión de forma indirecta y, por lo tanto, también usan el servicio de recuperación de URL.
cURL “lite”: cURL “lite” es una versión proporcionada por Google de la biblioteca cURL que usa el servicio de recuperación de URL en lugar del servicio de Sockets. Debes habilitar cURL “lite” en el archivo php.ini de tu aplicación.
Los siguientes métodos de extensión cURL no son compatibles:
curl_multi_* funciones
compatibilidad con protocolos no estándar
compatibilidad con puertos distintos a 80 (HTTP) o 443 (HTTPS)
Decidir si usar cURL, cURL Lite, o wrappers de flujo depende en gran medida de tu aplicación y de lo que prefieras. Si no estás seguro, usa la biblioteca HTTP Guzzle. Guzzle proporciona una capa de abstracción para las solicitudes HTTP, que te permite cambiar el servicio subyacente sin volver a escribir el código de la aplicación.
Controladores de transmisión
Los controladores de transmisión HTTP(S) estándar se usan en funciones de PHP integradas como fopen() y file_get_contents().
Habilita cURL o cURL “lite” en php.ini a fin de usar las funciones cURL para las solicitudes salientes. cURL “lite” usa el servicio de recuperación de URL, mientras que cURL usa la API de Sockets.
Según la configuración predeterminada, Guzzle usa el controlador de transmisión de PHP, pero usará un controlador cURL de manera automática en caso de que cURL o cURL “lite” esté habilitado.
Cómo establecer un tiempo de espera para la solicitud
Usa la opción timeout en el contexto HTTP para modificar el plazo.
Inhabilita los redireccionamientos
Si usas la recuperación de URL, el servicio de recuperación de URL subyacente sigue hasta cinco redireccionamientos de forma predeterminada. Estos redireccionamientos podrían reenviar información sensible, como los encabezados de autorización, al destino redireccionado. Si tu app no requiere redireccionamientos HTTP, se recomienda que los inhabilites.
Para indicarle al servicio de recuperación de URLs que no siga los redireccionamientos, tu app debe establecer el parámetro follow_location en las opciones de contexto HTTP en false.
Emite una solicitud HTTPS
De forma predeterminada, el servicio de recuperación de URL subyacente valida el certificado del host al que se conecta y rechaza las solicitudes si el certificado no coincide. No es necesario que protejas tu solicitud de forma explícita.
Inhabilita la validación del certificado del host
Según la configuración predeterminada, la implementación de App Engine del wrapper HTTPS intenta validar el certificado del host y rechaza las solicitudes en las que el certificado no coincida. Si deseas inhabilitar este comportamiento, establece el valor de verify_peer como false en las opciones de contexto de SSL/TLS.
Cómo emitir una solicitud dirigida a otra aplicación de App Engine
Cuando se emite una solicitud a otra app de App Engine, la tuya debe afirmar su identidad; para eso, se agrega el encabezado X-Appengine-Inbound-Appid a la solicitud.
Si le indicas al servicio de recuperación de URL que no siga los redireccionamientos, App Engine agregará este encabezado a las solicitudes de manera automática.
Obtén más información sobre el servicio de recuperación de URL, como los encabezados que se envían en una solicitud de recuperación de URL, en Solicitudes de salida.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[[["\u003cp\u003eThe \u003ccode\u003eREGION_ID\u003c/code\u003e 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.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine uses the URL Fetch service to handle outbound HTTP(S) requests, and PHP offers stream handlers, the cURL extension, and cURL "lite" for making these requests, each with different implementations and associated quotas.\u003c/p\u003e\n"],["\u003cp\u003eStream handlers use the URL Fetch service, the cURL extension uses the Sockets service (requiring billing to be enabled), and cURL "lite" is a Google-supplied version of the cURL library that also uses the URL Fetch service, and certain functions are unsupported.\u003c/p\u003e\n"],["\u003cp\u003eGuzzle HTTP library is recommended as it provides an abstraction layer for HTTP requests, enabling switching between services without code rewrites, and it uses stream handlers or cURL handlers based on availability.\u003c/p\u003e\n"],["\u003cp\u003eDisabling redirects is recommended for enhanced security, and if an app sends requests to another App Engine app, it must include the \u003ccode\u003eX-Appengine-Inbound-Appid\u003c/code\u003e header to assert its identity.\u003c/p\u003e\n"]]],[],null,["Region ID\n\nThe \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e is an abbreviated code that Google assigns\nbased on the region you select when you create your app. The code does not\ncorrespond to a country or province, even though some region IDs may appear\nsimilar to commonly used country and province codes. For apps created after\nFebruary 2020, \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e`.r` is included in\nApp Engine URLs. For existing apps created before this date, the\nregion ID is optional in the URL.\n\nLearn more\n[about region IDs](/appengine/docs/legacy/standard/php/how-requests-are-routed#region-id). \nOK\n\nThis page describes how to issue HTTP(S) requests from your App Engine\napp.\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| php-gen2\n|\n| /services/access). If you are updating to the App Engine PHP 7/8 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/php-differences) to learn about your migration options for legacy bundled services.\nApp 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](/appengine/docs/legacy/standard/php/outbound-requests).\n\nIssue an HTTP request\n\nThe PHP language provides several functions for making remote HTTP requests.\nThese are implemented in different ways in Google App Engine, and are subject to\ndifferent quotas and costs:\n\n- **Stream handlers** : The native `http://` and `https://` PHP stream handlers are configured to use App Engine's [URL Fetch service](/appengine/docs/legacy/standard/php/issue-requests) to make HTTP requests. Many PHP functions such as [file_get_contents()](http://php.net/manual/en/function.file-get-contents.php) use stream handlers indirectly, and thus also use the URL Fetch service.\n- **cURL extension** : The [cURL\n extension](http://php.net/manual/en/book.curl.php) uses the [Sockets service](/appengine/docs/legacy/standard/php/sockets). The cURL extension [must be enabled](/appengine/docs/legacy/standard/php/runtime#dynamically_loadable_extensions) in your application's [php.ini file](/appengine/docs/legacy/standard/php/config/php_ini) and billing must be enabled for your project.\n- **cURL \"lite\"** : cURL \"lite\" is a Google-supplied version of the cURL library that uses the [URL Fetch service](/appengine/docs/legacy/standard/php/issue-requests) instead of the Sockets service. You must enable cURL \"lite\" in your application's [php.ini file](/appengine/docs/legacy/standard/php/config/php_ini#GAE_directives). The following methods of the cURL extension are not supported:\n - `curl_multi_*` functions\n - support for non-standard protocols\n - support for ports other than 80 (HTTP) or 443 (HTTPS)\n\nDeciding whether to use cURL, cURL Lite, or stream wrappers depends largely on\nyour application and preference. If you are unsure, use the\n[Guzzle HTTP library](http://docs.guzzlephp.org/en/latest/index.html). Guzzle\nprovides an abstraction layer for HTTP requests, which allows you to change\nthe underlying service without rewriting application code. \n\nStream handlers\n\nThe standard HTTP(S) stream handlers are used in built-in PHP\nfunctions such as `fopen()` and `file_get_contents()`.\n\n\n $url = 'http://httpbin.org/post?query=update';\n $data = [\u003e'data' = &\u003e#39;this', 'data2' = 'that'];\n $headers = \"accept: */*\\r\\n\" .\n \"Content-Type: application/x-www-form-urlencoded\\r\\n\" .\n \"Custom-Header: custom-value\\r\\n\" .\n \u003e \"Custom-Heade\u003er-Two: custom-value-2\\r\\n&q\u003euot;;\n\n $context = [\n 'h\u003ettp' = [\n 'method' = 'POST',\n 'header' = $headers,\n 'content' = http_build_query($data),\n ]\n ];\n $context = stream_context_create($context);\n $result = file_get_contents($url, false, $context);\n\ncURL and cURL \"lite\"\n\n\nEnable cURL or cURL \"lite\" in php.ini to use cURL functions for outbound\nrequests. cURL \"lite\" uses the [URL Fetch service](/appengine/docs/legacy/standard/php/issue-requests),\nwhile cURL uses the [Sockets API](/appengine/docs/legacy/standard/php/sockets) \n\n $url = 'http://httpbin.org/post?query=update';\n $data = [\u003e'data' = &\u003e#39;this', 'data2' = 'that'];\n $headers = [\n 'Accept: */*',\n 'Content-Type: application/x-www-form-urlencoded',\n 'Custom-Header: custom-value',\n 'Custom-Header-Two: custom-value-2'\n ];\n\n // open connectio\u003en\n $ch = curl_init();\n\n // \u003eset curl options\n $options = [\n CURLO\u003ePT_URL = $url,\n CURLOPT_POST = count($data),\n \u003e CURLOPT_POSTFIELDS = http_build_query\u003e($data),\n CURLOPT_HTTPHEADER = $headers,\n CURLOPT_RETURNTRANSFER = true,\n ];\n curl_setopt_array($ch, $options);\n\n // execute\n $result = curl_exec($ch);\n\n // close connection\n curl_close($ch);\n\nGuzzle\n\nBy default, Guzzle uses PHP's stream handler, but will automatically use a\ncURL handler if cURL or cURL \"lite\" is enabled. \n\n $url = 'http://httpbin.org/post?query=update';\n $data = [\u003e'data' = &\u003e#39;this', 'data2' = '\u003e;that'];\n $headers = [\n \u003e 'Accept' = '*/*',\n 'Content-Type\u003e39; = 'application/x-www-form-urlencod\u003eed',\n 'Custom-Header' = 'custom-value',\n 'Custom-Header-Two' = 'custom-value',\n ];\n\n $guzzle = new GuzzleHttp\\Client;\n $re\u003equest = new GuzzleHttp\\Psr7\\Request('POST', $url, $headers, http_build_query($data));\n $result = $guzzle-send($request);\n\nSet a request timeout\n\nUse the `timeout` option in\n[HTTP context](https://php.net/manual/en/context.http.php) to alter\nthe deadline.\n\nDisable redirects **Important:** To improve the security of your app, it is recommended that you disable redirects.\n\nIf you are using URL Fetch, the underlying URL Fetch service follows up to five\nredirects by default. These redirects could forward sensitive information, such\nas authorization headers, to the redirected destination. If your app does not\nrequire HTTP redirects, it is recommended that you disable the redirects.\n\nTo instruct the URL Fetch service to not follow redirects, your app must\nset the `follow_location` parameter in the\n[HTTP context options](https://php.net/manual/en/context.http.php)\nto `false`.\n\nIssue an HTTPS request\n\nBy default, the underlying URL Fetch service validates the certificate\nof the host it contacts, and rejects requests if the certificate\ndoesn't match. You don't need to explicitly secure your request.\n\nDisable host certificate validation\n\nBy default, the App Engine implementation of the HTTPS wrapper attempts\nto validate the certificate of the host, and rejects requests where the\ncertificate does not match. To disable this behavior, set the value of\n`verify_peer` to `false` in the\n[SSL/TLS context options](https://php.net/manual/en/context.ssl.php).\n| **Note:** The URL Fetch service ignores all other SSL/TLS context options.\n\nIssue a request to another App Engine app\n\nWhen issuing a request to another App Engine app, your App Engine app\nmust assert its identity by adding the header `X-Appengine-Inbound-Appid`\nto the request.\nIf you instruct the URL Fetch service to not follow redirects, App Engine\nwill add this header to requests automatically.\n\nSee [Disabling redirects](#disabling_redirects) for guidance on disabling\nredirects.\n| **Note:** If you are making requests to another App Engine application, use its \u003cvar translate=\"no\"\u003e\u003ca href=\"#appengine-urls\" style=\"border-bottom: 1px dotted #999\" class=\"devsite-dialog-button\" data-modal-dialog-id=\"regional_url\" track-type=\"progressiveHelp\" track-name=\"modalHelp\" track-metadata-goal=\"regionalURL\"\u003eREGION_ID\u003c/a\u003e\u003c/var\u003e`.r.appspot.com` domain name rather than a custom domain for your app.\n\nWhat's next\n\nLearn about the URL Fetch service, such as the headers that are\nsent in a URL Fetch request in [Outbound Requests](/appengine/docs/legacy/standard/php/outbound-requests)."]]