2.2Sending Request Data
Created on Aug 17, 2026~1 min read
When retrieving data from third-party APIs, you usually need to carry request data, which can be URL address parameters or request content. The most common approaches are passing parameters through the URL address and sending JSON-formatted data.
var content = await httpRemoteService.PostAsAsync<YourRemoteModel>("https://localhost:7044/HttpRemote/AddModel", builder => builder .WithQueryParameters(new { query1 = 1, query2 = "furion" }) // Set URL query parameters .SetJsonContent(new { id = 1, name = "furion" })); // Set the request's JSON contentIn addition to the above approach, the following methods are also supported:
// Using the builder patternvar content = await httpRemoteService.SendAsAsync<YourRemoteModel>(HttpRequestBuilder.Post("https://localhost:7044/HttpRemote/AddModel") .WithQueryParameter("query1", 1) // Set query parameters (supports individual setting) .WithQueryParameter("query2", "furion") // Set query parameters (supports individual setting) .SetJsonContent("{\"id\":1,\"name\":\"furion\"}")); // Set request content (supports passing a JSON string directly)// For more detailed usage, see section 2.1In addition, you can use the SetContent method to set request content, which supports setting any type of request content. In fact, the SetJsonContent method is also implemented internally by calling SetContent.
// Custom Content-Typevar content = await httpRemoteService.PostAsAsync<YourRemoteModel>("https://localhost:7044/HttpRemote/AddModel", builder => builder .WithQueryParameters(new { query1 = 1, query2 = "furion" }) // Set query parameters .SetContent(new { id = 1, name = "furion" }, "application/json")); // Set request content// Custom Content-Type supports configuring Charsetvar content = await httpRemoteService.PostAsAsync<YourRemoteModel>("https://localhost:7044/HttpRemote/AddModel", builder => builder .WithQueryParameters(new { query1 = 1, query2 = "furion" }) // Set query parameters .SetContent(new { id = 1, name = "furion" }, "application/json;charset=utf-8")); // Set request content// Custom Content-Type supports configuring request encodingvar content = await httpRemoteService.PostAsAsync<YourRemoteModel>("https://localhost:7044/HttpRemote/AddModel", builder => builder .WithQueryParameters(new { query1 = 1, query2 = "furion" }) // Set query parameters .SetContent(new { id = 1, name = "furion" }, "application/json;charset=utf-8", Encoding.UTF8)); // Set request content