3.8Setting JSON Content
Created on Aug 17, 2026~3 min read
Sets the request's content type to application/json and sends JSON data.
HttpRequestBuilder.Post("https://furion.net/") .SetJsonContent(new { id = 1, name = "Furion" }); // Supports anonymous objects or typed objectsHttpRequestBuilder.Post("https://furion.net/") .SetJsonContent("{\"id\":1,\"name\":\"furion\"}"); // Sends a JSON string directlyHttpRequestBuilder.Post("https://furion.net/") .SetJsonContent("{\"id\":1,\"name\":\"furion\"}", Encoding.UTF8); // Sets the encodingHttpRequestBuilder.Post("https://furion.net/") .SetJsonContent("{\"id\":1,\"name\":\"furion\"}", Encoding.UTF8, "application/json-patch+json"); // Custom content-typeHttpRequestBuilder.Post("https://furion.net/") .SetJsonContent(new { id = 1, name = "Furion" }, jsonSerializerOptions: new JsonSerializerOptions()); // Supports passing a JsonSerializerOptions objectHttpRequestBuilder.Post("https://furion.net/") .SetJsonContentWithoutValidation("{\"id\":1,\"name\":\"furion\"}"); // Sends a JSON string directly (without validating the JSON format)