2016-09-23 666 views
2

我正在使用POSTMAN发送字符串数组到web api。在Web API方法看起来像如何使用POSTMAN发布字符串数组?

[HttpPost] 
    public async Task<IEnumerable<DocumentDTO>> GetDocuments([FromBody]IEnumerable<string> documentNames) 
    { 
     return await _service.GetDocuments(documentNames); 
    } 

我看到这个SO post这里如何使用邮递员送阵列。所以在这里我是如何发送阵列 enter image description here

提琴手显示请求的内容类型是multipart/form-data;

enter image description here

但我得到错误响应,

{“消息”:“其请求实体的媒体类型'multipart/form-data' 不支持此资源。“,”ExceptionMessage“:”否 MediaTypeFormatter is availabl E要读类型的对象 “的IEnumerable 1' from content with media type 'multipart/form-data'.", "ExceptionType": "System.Net.Http.UnsupportedMediaTypeException",
"StackTrace": " at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable
1格式化器,IFormatterLogger formatterLogger,的CancellationToken的CancellationToken个)\ r \ n在 System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage 请求,类型类型,IEnumerable`1格式化,IFormatterLogger formatterLogger,的CancellationToken的CancellationToken)”}

我试图设定键作为documentNamesdocumentNames[]documentNames[0]
我试图选择身体x-www-form-urlencoded。当我这样做时,API收到空集合。
我试过选择身体作为raw当我这样做的API接收null作为参数。

问题
1>如何使用表单数据发送字符串数组?
1>如何使用x-www-form-urlencoded发送字符串数组。 ?
2>如何发送字符串数组作为原始json?

回答

6

将它作为JSON阵列和选择raw选项像下面

enter image description here

对于API方法签名

public void Post([FromBody] IEnumerable<string> value) 
    { 
     //some processing 
    } 
相关问题