ExceptionMessage“: ”No MediaTypeFormatter is available to read an object of type 'user' from content with media type 'multipart/form-data in “postman”
-
22-12-2019 - |
Question
I am creating the Login Service using Web API. When I am checking with fiddler
it's working fine but when I am checking with postman
of chrome
it's showing error:
{ "Message": "An error has occurred.",
"ExceptionMessage": "No MediaTypeFormatter is available to read an object of type 'user' from content with media type 'multipart/form-data'.",
"ExceptionType": "System.InvalidOperationException",
"StackTrace": "
at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n
at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n
at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n
at System.Web.Http.ModelBinding.FormatterParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)\r\n
at System.Web.Http.Controllers.HttpActionBinding.<>c__DisplayClass1.<ExecuteBindingAsync>b__0(HttpParameterBinding parameterBinder)\r\n
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()\r\n
at System.Threading.Tasks.TaskHelpers.IterateImpl(IEnumerator`1 enumerator, CancellationToken cancellationToken)"
}
public class user
{
//public user(string userId, string password)
//{
// UserId = userId;
// Password = password;
//}
public string UserId { get; set; }
public string Password { get; set; }
}
I am checking in postman
if this service is able to access in mobile application. Also, to check this in mac system.
Solution
Click on the Header button type this both header and value
Content-Type: application/json
check below link for fiddle and postman both use same content-types Error sending json in POST to web API service
OTHER TIPS
I run into same problem but later I figured it out that I was calling WebAPI using ajax POST instead I changed it to GET and it worked. But error was mostly misguiding. So all the time I was focusing on media type.
The request entity's media type 'text/plain' is not supported for this resource.",
$http({
method: 'POST',
Change it to
$http({
method: '**GET**',