Content Types

ByteArrayContent

Send content encoded as a byte array

C#
ByteArrayContent byteArrayContent = new ByteArrayContent(new byte[10] { 0,1,2,3,4,5,6,7,8,9 }, "text/plain");

FormUrlEncodedContent

Send content encoded as key/value pairs

C#
Dictionary<string, string> data = new Dictionary<string, string>() { { "name1", "value1" }, { "name2", "value2" } }; FormUrlEncodedContent formUrlEncodedContent = new FormUrlEncodedContent(data);

MultipartContent

Send a combination of different HttpContents

C#
StringContent stringContent = new StringContent("Hello World", Encoding.UTF8, "text/plain"); ByteArrayContent byteArrayContent = new ByteArrayContent(new byte[10] { 0,1,2,3,4,5,6,7,8,9 }, "text/plain"); MultipartContent multipartContent = new MultipartContent("ABoundary", "subtype"); multipartContent.Add(stringContent); multipartContent.Add(byteArrayContent);

MultipartFormDataContent

Send a combination of different HttpContents with field or filenames

C#
StringContent stringContent = new StringContent("Hello World", Encoding.UTF8, "text/plain"); ByteArrayContent byteArrayContent = new ByteArrayContent(new byte[10] { 0,1,2,3,4,5,6,7,8,9 }, "text/plain"); MultipartFormDataContent multipartFormDataContent = new MultipartFormDataContent("ABoundary"); multipartFormDataContent.Add(stringContent, "Field1"); multipartFormDataContent.Add(byteArrayContent, "Field2", "File.txt");

StreamContent

Send content based on a stream

C#
FileStream fileStream = new FileStream("AText.txt", FileMode.Open); StreamContent streamContent = new StreamContent(fileStream, "text/plain");

StringContent

Send content encoded as a string

C#
StringContent stringContent = new StringContent("Hello World", Encoding.UTF8, "text/plain");

Automically convert an object to json

C#
var myObject = new MyObject(); StringContent stringContent = StringContent.FromObject(myObject);