【发布时间】:2017-01-09 21:07:38
【问题描述】:
我需要使用HttpClient 将过滤参数传递给 ASP.NET Core REST API Server。
过滤器包含复杂的数据类型。我曾经通过HttpPost传递数据,但它不适合CRUD概念。
如何在 HttpGet 请求中将复杂数据类型作为 json 对象发送?
【问题讨论】:
-
查询字符串参数
标签: c# asp.net-core asp.net-core-webapi
我需要使用HttpClient 将过滤参数传递给 ASP.NET Core REST API Server。
过滤器包含复杂的数据类型。我曾经通过HttpPost传递数据,但它不适合CRUD概念。
如何在 HttpGet 请求中将复杂数据类型作为 json 对象发送?
【问题讨论】:
标签: c# asp.net-core asp.net-core-webapi
您可以通过定义自己的 Get 方法来实现 例如:
static async Task<HttpResponseMessage> GetAsync(this HttpClient client, string uri, HttpContent content, CancellationToken cancelToken)
{
var request = new HttpRequestMessage(new HttpMethod("GET"), uri)
{
Content = content
};
return await client.SendAsync(request, cancelToken);
}
但是!不建议这样做,请在此处阅读:HTTP GET with request body
更好的解决方案是将复杂对象转换为 URL 参数
【讨论】: