http - 发送复杂对象 GET 与 POST

标签 http asp.net-web-api get

我想知道什么是最好的方法是发送一个复杂的对象,当它只是为了查找数据的目的。我有一个网格,其中将在服务器端完成分页、过滤、排序等。所以我必须在每个请求中发送所有这些数据。

public class DataConfiguratorDto
{
    [Required]
    public Paging Paging { get; set; }

    public Sorting Sorting { get; set; }

    public IList<Filtering> FlitersList { get; set; }
}

public enum FilterCondition
{
    Equals,
    Contains,
    MoreThan,
    LessThan,
}

public class Paging
{
    public int RowNumberStart { get; set; }

    [GreaterThan(nameof(RowNumberStart))]
    public int RowNumberEnd { get; set; }
}

public class Filtering
{
    [Required]
    public string ColumnName { get; set; }

    [Required]
    public object FilterValue { get; set; }

    [Required]
    public FilterCondition FilterCondition { get; set; }

    [Required]
    public FilterType FilterType { get; set; }
}

public class Sorting
{
    [Required]
    public SortOption SortOption;

    [Required]
    public string ColumnName { get; set; }
}

public enum SortOption
{
    Asc,
    Desc
}

public enum FilterType
{
    And,
    Or
}

现在我可以使用 POST,但这不是破坏了它的目的吗?

执行此操作的最佳选择是什么?

最佳答案

您应该使用帖子,在正文中发送复杂对象(例如 JSON)。

根据 W3.org

“GET 方法意味着检索由 Request-URI 标识的任何信息(以实体的形式)。”

“POST 方法用于请求源服务器接受请求中包含的实体作为请求行中 Request-URI 标识的资源的新下属。”

参见 here了解更多信息。

关于http - 发送复杂对象 GET 与 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42008541/

相关文章:

c# - MVC WebApi 端点不适用于生产环境,但常规端点可以

http - 使用 ioutil : returning array of (ASCII? ) 来自 http 调用的数字进行输出

http - 从 Windows Powershell 发送 HTTP 请求的最佳方式是什么?

c - 简单的网络服务器

c# - 在 webapi 中使用 OData 获取仅在运行时已知的属性

json - 差异 : JSONP vs GET

python - 用于 Python 中的 SOAP 服务器的极简主义非企业方法

url - 值为空字符串的 WebApi 请求 URL

http - 程序在执行 GET 请求时连续超时后停止

php 使用上一页中的参数选择查询