2016-09-23 61 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 
    } 
相關問題