Function: http.post Stay organized with collections Save and categorize content based on your preferences.
Sends an HTTPPOST request to the specified URL.
For more information, seeMake an HTTP request.
Arguments
| Arguments | |
|---|---|
url |
The URL to send the request to. |
timeout |
The request timeout, in seconds (default: |
body | If present, the request body (POST requests do generally require a body). If aContent-Type header is not specified and if the body value is bytes, the header is set toContent-Type: application/octet-stream; otherwise, the body is JSON-encoded and the header is set toContent-type: application/json; charset=utf-8. |
headers | The HTTP request headers. If present, must be a map of strings. If aContent-Type header is specified, the request body is encoded as prescribed. For example, it might be JSON or URL-encoded. |
query | Optional query parameters. If present, must be a map that will get URL-encoded and appended to the URL. The map values must be strings, ints, floats, booleans, or lists of those. |
auth | Optional authentication properties. If present, must be a map withtype attribute in["OIDC", "OAuth2"]. Ascopes key is also supported. For details, seeMake authenticated requests to Google Cloud APIs. |
private_service_name |
If present, |
ca_certificate |
If present, |
Returns
The HTTP response as a map withbody,code (status code), andheadersattributes.
Raised exceptions
| Exceptions | |
|---|---|
ConnectionError | In case of a network problem (DNS failure, truncated response, etc.). |
ConnectionFailedError | When the connection is halted during transfer (failed connection, refused connection, etc.). |
TimeoutError | When the specified timeout is reached before the response is received. |
HttpError | If the response status is >= 400. |
ValueError | If timeout is > 1800. If the URL is invalid or if authType is present and URL is invalid for the given authType. If the private_service_name is invalid. If private_service_name is present and URL contains a port. If ca_certificate is present and not of type bytes. |
Examples
# Make a `POST` request to an external HTTP endpoint-send_message:call:http.postargs:url:https://www.example.com/endpointbody:some_val:"HelloWorld"another_val:123result:the_message-return_value:return:${the_message.body}
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.