3.8设置 JSON 内容
创建于 2026 年 8 月 17 日约 1 分钟读完
将请求的内容类型设置为 application/json 并发送 JSON 数据。
HttpRequestBuilder.Post("https://furion.net/") .SetJsonContent(new { id = 1, name = "Furion" }); // 支持匿名对象或类型对象HttpRequestBuilder.Post("https://furion.net/") .SetJsonContent("{\"id\":1,\"name\":\"furion\"}"); // 直接发送 JSON 字符串HttpRequestBuilder.Post("https://furion.net/") .SetJsonContent("{\"id\":1,\"name\":\"furion\"}", Encoding.UTF8); // 设置编码HttpRequestBuilder.Post("https://furion.net/") .SetJsonContent("{\"id\":1,\"name\":\"furion\"}", Encoding.UTF8, "application/json-patch+json"); // 自定义 content-typeHttpRequestBuilder.Post("https://furion.net/") .SetJsonContent(new { id = 1, name = "Furion" }, jsonSerializerOptions: new JsonSerializerOptions()); // 支持传入 JsonSerializerOptions 对象HttpRequestBuilder.Post("https://furion.net/") .SetJsonContentWithoutValidation("{\"id\":1,\"name\":\"furion\"}"); // 直接发送 JSON 字符串(不会校验 JSON 格式有效性)