# Class UrlEncodedContent (2.1.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.1.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.UrlEncodedContent)
- [2.0.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/2.0.3/com.google.api.client.http.UrlEncodedContent)
- [1.47.1](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.47.1/com.google.api.client.http.UrlEncodedContent)
- [1.46.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.46.3/com.google.api.client.http.UrlEncodedContent)
- [1.45.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.45.3/com.google.api.client.http.UrlEncodedContent)
- [1.44.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.44.2/com.google.api.client.http.UrlEncodedContent)
- [1.43.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.43.2/com.google.api.client.http.UrlEncodedContent)
- [1.42.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.42.3/com.google.api.client.http.UrlEncodedContent)
- [1.41.8](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.41.8/com.google.api.client.http.UrlEncodedContent)

    public class UrlEncodedContent extends AbstractHttpContent

Implements support for HTTP form content encoding serialization of type `
application/x-www-form-urlencoded` as specified in the [HTML 4.0 Specification](http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1).

Sample usage:

static void setContent(HttpRequest request, Object item) {
request.setContent(new UrlEncodedContent(item));
}

Implementation is not thread-safe.

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> [AbstractHttpContent](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractHttpContent) \> UrlEncodedContent

## Inherited Members

[AbstractHttpContent.computeLength()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractHttpContent#com_google_api_client_http_AbstractHttpContent_computeLength__) [AbstractHttpContent.computeLength(HttpContent)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractHttpContent#com_google_api_client_http_AbstractHttpContent_computeLength_com_google_api_client_http_HttpContent_) [AbstractHttpContent.getCharset()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractHttpContent#com_google_api_client_http_AbstractHttpContent_getCharset__) [AbstractHttpContent.getLength()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractHttpContent#com_google_api_client_http_AbstractHttpContent_getLength__) [AbstractHttpContent.getMediaType()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractHttpContent#com_google_api_client_http_AbstractHttpContent_getMediaType__) [AbstractHttpContent.getType()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractHttpContent#com_google_api_client_http_AbstractHttpContent_getType__) [AbstractHttpContent.retrySupported()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractHttpContent#com_google_api_client_http_AbstractHttpContent_retrySupported__) [AbstractHttpContent.setMediaType(HttpMediaType)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractHttpContent#com_google_api_client_http_AbstractHttpContent_setMediaType_com_google_api_client_http_HttpMediaType_) [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### getContent(HttpRequest request)

    public static UrlEncodedContent getContent(HttpRequest request)

Returns the URL-encoded content of the given HTTP request, or if none return and set as content
a new instance of [UrlEncodedContent](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.UrlEncodedContent) (whose [#getData()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.UrlEncodedContent#com_google_api_client_http_UrlEncodedContent_getData__) is an implementation of
[Map](https://docs.oracle.com/javase/8/docs/api/java/util/Map.html)).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpRequest` HTTP request |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.UrlEncodedContent` | URL-encoded content |

## Constructors

### UrlEncodedContent(Object data)

    public UrlEncodedContent(Object data)

Initialize the UrlEncodedContent with the legacy and deprecated escapeUri encoder

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `data` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` key name/value data |

### UrlEncodedContent(Object data, boolean useUriPathEncoding)

    public UrlEncodedContent(Object data, boolean useUriPathEncoding)

Initialize the UrlEncodedContent with or without the legacy and deprecated escapeUri encoder

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `data` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` key name/value data |
| `useUriPathEncoding` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` escapes the string value so it can be safely included in URI path segments. For details on escaping URIs, see [RFC 3986 - section 2.4](http://tools.ietf.org/html/rfc3986#section-2.4) |

## Methods

### getData()

    public final Object getData()

Returns the key name/value data or `null` for none.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |   |

### setData(Object data)

    public UrlEncodedContent setData(Object data)

Sets the key name/value data.

Overriding is only supported for the purpose of calling the super implementation and
changing the return type, but nothing else.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `data` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.UrlEncodedContent` |   |

### setMediaType(HttpMediaType mediaType)

    public UrlEncodedContent setMediaType(HttpMediaType mediaType)

Sets the media type to use for the Content-Type header, or `null` if unspecified.

This will also overwrite any previously set parameter of the media type (for example `
"charset"`), and therefore might change other properties as well.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `mediaType` | `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpMediaType` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.UrlEncodedContent` |   |

**Overrides** [AbstractHttpContent.setMediaType(HttpMediaType mediaType)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractHttpContent#com_google_api_client_http_AbstractHttpContent_setMediaType_com_google_api_client_http_HttpMediaType_)

### writeTo(OutputStream out)

    public void writeTo(OutputStream out)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `out` | `https://docs.oracle.com/javase/8/docs/api/java/io/OutputStream.html` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |