3.71Appending Request Content

Created on Aug 17, 2026~4 min read

When you need to dynamically add more data to existing request content without affecting the already-set ContentType and ContentEncoding, you can use the AppendContent() method. This method intelligently merges based on the types of the existing content and the incoming content:

Existing content typeIncoming content typeMerge behavior
stringstringConcatenated using the & symbol (commonly used for application/x-www-form-urlencoded)
StringBuilderstringThe incoming string is appended to the end of the StringBuilder
IDictionary<string, object?>IDictionary<string, object?>The two dictionaries are merged, and the value is updated for existing keys
NameValueCollectionNameValueCollection or IDictionary<string, object?>Key-value pairs are merged, and a key with the same name can retain multiple values; dictionary values are converted to strings before being added
IListIEnumerable (non-string)The elements of the incoming collection are appended to the list in order
Any other typeAny typeDirectly overwrites the original content
cs
// String concatenation: one call appends, and multiple calls can append successivelyHttpRequestBuilder.Post("https://furion.net/")    .SetContent("a=1", "application/x-www-form-urlencoded")    .AppendContent("b=2");    // Result: a=1&b=2// Append a string to a StringBuildervar sb = new StringBuilder("a=1");HttpRequestBuilder.Post("https://furion.net/")    .SetContent(sb, "application/x-www-form-urlencoded")    .AppendContent("&b=2");   // sb content becomes "a=1&b=2"// Dictionary merge: existing key values are updatedvar dict = new Dictionary<string, object?> { ["key1"] = "val1" };HttpRequestBuilder.Post("https://furion.net/")    .SetContent(dict, "application/x-www-form-urlencoded")    .AppendContent(new Dictionary<string, object?> { ["key2"] = "val2" }); // Merged into { key1: val1, key2: val2 }// NameValueCollection merge (a key with the same name retains multiple values)var nvc = new NameValueCollection { ["id"] = "1" };HttpRequestBuilder.Post("https://furion.net/")    .SetContent(nvc, "application/x-www-form-urlencoded")    .AppendContent(new NameValueCollection { ["name"] = "furion", ["name"] = "dotnet" }); // "name" has two values// List append: add new elements to an existing listvar list = new List<string> { "item1" };HttpRequestBuilder.Post("https://furion.net/")    .SetContent(list, "application/json")    .AppendContent(new[] { "item2" });   // Result: ["item1", "item2"]// Other type overwrite: replace the old content with the new contentHttpRequestBuilder.Post("https://furion.net/")    .SetContent("original")    .AppendContent(new { id = 1 });      // RawContent becomes { id = 1 }