I am using Postman to send an array of string to a web API. The web API method looks like:
[HttpPost]
public async Task<IEnumerable<DocumentDTO>> GetDocuments([FromBody]IEnumerable<string> documentNames)
{
return await _service.GetDocuments(documentNames);
}
I saw this SO post on how to send an array using Postman. Here is how I am sending the array:
Fiddler shows the request's content type is multipart/form-data;
But I am getting an error response:
{ "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 'IEnumerable
1' from content with media type 'multipart/form-data'.", "ExceptionType": "System.Net.Http.UnsupportedMediaTypeException",
1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)" }
"StackTrace": " at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable
I have tried setting the key as documentNames
,documentNames[]
, documentNames[0]
.
I have tried selecting the body as x-www-form-urlencoded
. When I do that, the API receives an empty collection.
I have tried selecting a body as raw
. When I do that, the API receives null as a parameter.
Questions
x-www-form-urlencoded
? Pass it as JSON array and select the raw
option like below
For a API method signature
public void Post([FromBody] IEnumerable<string> value)
{
//some processing
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With