在Web API端点中传递多个数据列表

时间:2018-12-19 03:08:25

标签: .net rest asp.net-web-api

我有Web api端点

[HttpPut]
 public async Task<IHttpActionResult> Rights(
       [FromBody] IEnumerable<Rights> rights,
       [FromBody] IEnumerable<Permissions> permissions)

任何想法我如何在请求的正文中传递这两个数组参数。我的代码是这样的

public static async Task Request(this RequestData requestData, Context context)
        {
            var url = requestData.GetAbsoluteUrl();

            byte[] body = Encoding.UTF8.GetBytes(Serialize(requestData.Body, requestData.Body.GetType()));

            using (var client = new CustomWebClient(context, body))
            {
                client.Headers.Add("Content-Type", "application/json");
                await client.UploadAsync(url, requestData.Method.ToString(), body);
            }
        }

1 个答案:

答案 0 :(得分:1)

public class RequestBody
{
 public IEnumerable<Rights> rights
 public IEnumerable<Permissions> permissions
}

将此类对象发送为RequestData