FormUrlEncodedFormatter Class

Namespace
Kampute.HttpClient.Content
Assembly
  • Kampute.HttpClient.dll

Definition

Writes collections of key-value pairs as URL-encoded form content.
public sealed class FormUrlEncodedFormatter : HttpContentFormatter
Inheritance

Remarks

This formatter is send-only: it writes payloads that implement IEnumerable<T> of KeyValuePair<TKey, TValue> with string keys and values as application/x-www-form-urlencoded content, and does not read responses. The form helpers of HttpRestClientFormExtensions use it.

Constructors

FormUrlEncodedFormatter()

Initializes a new instance of the FormUrlEncodedFormatter class.
public FormUrlEncodedFormatter()

Methods

CanWriteType(Type)

Determines whether the payload type is a collection of string key-value pairs.
protected override bool CanWriteType(Type payloadType)

Parameters

payloadType Type
The type of the payload to write.

Returns

bool
true if payloadType implements IEnumerable<T> of KeyValuePair<TKey, TValue> with string keys and values; otherwise, false.

CreateContent(object, string)

Creates URL-encoded form content from the payload.
protected override HttpContent CreateContent(object payload, string mediaType)

Parameters

payload object
The collection of key-value pairs to write.
mediaType string
The media type of the content to create.

Returns

HttpContent
A FormUrlEncodedContent that carries payload.