3.3JSON / HTML / XML 内容
将请求的内容类型设置为 application/json 并发送 JSON 数据。
设置 JSON 内容 ✨#
将请求的内容类型设置为 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 格式有效性)设置 HTML 内容#
将请求的内容类型设置为 text/html 并发送 HTML 数据。
HttpRequestBuilder.Post("https://furion.net/") .SetHtmlContent("<html></html>");HttpRequestBuilder.Post("https://furion.net/") .SetHtmlContent("<html></html>", Encoding.UTF8); // 设置编码HttpRequestBuilder.Post("https://furion.net/") .SetHtmlContent("<html></html>", Encoding.UTF8, "application/html"); // 自定义 content-type设置 XML 内容#
将请求的内容类型设置为 text/xml 并发送 XML 数据。
HttpRequestBuilder.Post("https://furion.net/") .SetXmlContent("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");HttpRequestBuilder.Post("https://furion.net/") .SetXmlContent("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", Encoding.UTF8); // 设置编码HttpRequestBuilder.Post("https://furion.net/") .SetXmlContent("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", Encoding.UTF8, "application/soap+xml"); // 自定义 content-type