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 type | Incoming content type | Merge behavior |
|---|---|---|
string | string | Concatenated using the & symbol (commonly used for application/x-www-form-urlencoded) |
StringBuilder | string | The 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 |
NameValueCollection | NameValueCollection 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 |
IList | IEnumerable (non-string) | The elements of the incoming collection are appended to the list in order |
| Any other type | Any type | Directly overwrites the original content |
// 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 }