我正在使用Postman将一个字符串数组发送到Web API。 Web API方法如下所示:
[HttpPost]
public async Task<IEnumerable<DocumentDTO>> GetDocuments([FromBody]IEnumerable<string> documentNames)
{
return await _service.GetDocuments(documentNames);
}
我看到这个SO post关于如何使用Postman发送数组。以下是我发送数组的方式:
Fiddler显示请求的内容类型是multipart/form-data;
但我收到错误回复:
{“Message”:“此资源不支持请求实体的媒体类型'multipart / form-data'。”,“ExceptionMessage”:“没有MediaTypeFormatter可用于读取'IEnumerable
1' from content with media type 'multipart/form-data'.", "ExceptionType": "System.Net.Http.UnsupportedMediaTypeException",
1格式化程序,IFormatterLogger formatterLogger,CancellationToken类型的对象cancelToken)\ r \ n在System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage请求,类型类型,IEnumerable`1格式化程序,IFormatterLogger formatterLogger,CancellationToken cancellationToken)“}
"StackTrace": " at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable
我已经尝试将密钥设置为documentNames
,documentNames[]
,documentNames[0]
。
我试过选择身体作为x-www-form-urlencoded
。当我这样做时,API会收到一个空集合。
我试过选择一个身体作为raw
。当我这样做时,API接收null作为参数。
问题
x-www-form-urlencoded
发送字符串数组?