[英]How to post string array using POSTMAN?
我正在使用 Postman 將字符串數組發送到 Web API。 Web API 方法如下所示:
[HttpPost]
public async Task<IEnumerable<DocumentDTO>> GetDocuments([FromBody]IEnumerable<string> documentNames)
{
return await _service.GetDocuments(documentNames);
}
我看到了這篇關於如何使用 Postman 發送數組的帖子。 這是我發送數組的方式:
Fiddler 顯示請求的內容類型是multipart/form-data;
但我收到錯誤響應:
{ "Message": "該資源不支持請求實體的媒體類型 'multipart/form-data'。", "ExceptionMessage": "沒有 MediaTypeFormatter 可用於
1' from content with media type 'multipart/form-data'.", "ExceptionType": "System.Net.Http.UnsupportedMediaTypeException",
讀取類型為 'IEnumerable
"StackTrace": " at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable1' 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, IEnumerable1' 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, IEnumerable1' 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, IEnumerable1' from content with media type 'multipart/form-data'.", "ExceptionType": "System.Net.Http.UnsupportedMediaTypeException",
1 格式化程序、IFormatterLogger formatterLogger、CancellationToken CancellationToken)\\r\\n 在 System.Web.Http.ModelBinding.FormatterParameterBinding。 ReadContentAsync(HttpRequestMessage 請求,類型類型,IEnumerable`1 格式化程序,IFormatterLogger formatterLogger,CancellationToken 取消令牌)" }
"StackTrace": " at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable
我嘗試將密鑰設置為documentNames
、 documentNames[]
、 documentNames[0]
。
我曾嘗試將正文選擇為x-www-form-urlencoded
。 當我這樣做時,API 收到一個空集合。
我試過選擇一個 body 作為raw
。 當我這樣做時,API 接收 null 作為參數。
問題
x-www-form-urlencoded
發送字符串數組?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.