FormUrlEncodedHandler

The FormUrlEncodedHandler allows you to post using “application/x-www-form-urlencoded” data.

To use it simply call the UseFormUrlEncodedHandler() extension method and set the header Content-Type to “application/x-www-form-urlencoded” and use as normal.

var config = new Config() //Build a pipeline using extension methods
                    .UseFormUrlEncodedHandler();

dynamic client = new RestClient("https://jsonplaceholder.typicode.com", config);
var user = new User { name="foo", email="foo@bar.com" };

//PUT name=foo&email=foo@bar.com  https://jsonplaceholder.typicode.com/users/1
var result = await client
      .Headers(new Headers { { "Content-Type", "application/x-www-form-urlencoded" }})
      .User(1)
      .Put(user);

Simple Array Example

var config = new Config() //Build a pipeline using extension methods
                    .UseFormUrlEncodedHandler();

dynamic client = new RestClient("https://jsonplaceholder.typicode.com", config);
var user = new User { name="foo", emailAddresses=new[] {"foo@bar.com", "x@x.com"} };

//PUT name=foo&emailAddresses=foo@bar.com&emailAddresses=x@x.com  https://jsonplaceholder.typicode.com/users/1
var result = await client
      .Headers(new Headers { { "Content-Type", "application/x-www-form-urlencoded" }})
      .User(1)
      .Put(user);

Complex arrays and nested objects

Form bodies are flattened exactly the same way as query strings - arrays of objects become user[0].FirstName=George&user[1].FirstName=Abraham and nested objects become user.name=foo&user.email=foo@bar.com. See Query Strings for the full set of shapes, they all apply here.

Updated: