[HttpPost] public async Task<IEnumerable<DocumentDTO>> GetDocuments([FromBody]IEnumerable<string> documentNames) { return await _service.GetDocuments(documentNames); }
我在SO post上看到了如何使用Postman发送数组.这是我发送数组的方式:
fiddler显示请求的内容类型是multipart / form-data;
{ “Message”: “The request entity’s media type ‘multipart/form-data’
is not supported for this resource.”,“ExceptionMessage”: “No
MediaTypeFormatter is available to read an object of type
‘IEnumerable1' from content with media type 'multipart/form-data'.",
1 formatters,IFormatterLogger
"ExceptionType": "System.Net.Http.UnsupportedMediaTypeException",
"StackTrace": " at
System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent
content,Type type,IEnumerable
formatterLogger,CancellationToken cancellationToken)\r\n at
System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage
request,IEnumerable`1 formatters,CancellationToken cancellationToken)” }
我已经尝试将密钥设置为documentNames,documentNames [],documentNames [0].
我尝试选择身体为x-www-form-urlencoded.当我这样做时,API会收到一个空集合.
我试过选择一个原始的身体.当我这样做时,API接收null作为参数.
问题
>如何使用表单数据发送字符串数组?
>如何使用x-www-form-urlencoded发送字符串数组?
>如何将字符串数组作为原始JSON发送?
解决方法
对于API方法签名
public void Post([FromBody] IEnumerable<string> value) { //some processing }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。