aspnet / WebHooks

[Archived] Libraries to create and consume web hooks on ASP.NET Core. Project moved to https://github.com/aspnet/AspLabs
Apache License 2.0
627 stars 439 forks source link

No MediaTypeFormatter is available to read an object of type 'JToken' from content with media type 'application/vnd.api+json' #83

Closed kadevu closed 6 years ago

kadevu commented 8 years ago

I am using GenericJsonWebHook and it throws an exception

The WebHook request contained invalid JSON: 'No MediaTypeFormatter is available to read an object of type 'JToken' from content with media type 'application/vnd.api+json'.'

POST /api/webhooks/incoming/genericjson?code=12345678901234567890123456789012 HTTP/1.1
Content-Type: application/vnd.api+json; charset=utf-8
Host: localhost:1234
Content-Length: 19
X-Amz-Date: 20160912T102556Z
Authorization: AWS4-HMAC-SHA256 Credential=/20160912/us-east-1/execute-api/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=e3a63edf905e6dec6a36e8fce504bda27ad69ec51af07dedb12ff0cc34ff4202
Cache-Control: no-cache
Postman-Token: d8f30232-ae6e-c199-1317-4416356abf3a

{
  "data": "Sample string"
}

But when I change the Content-Type to application/json, it works just fine.

HenrikFrystykNielsen commented 8 years ago

Hi there!

We use the same formatters that Web API defines natively which means that we handle the same media types as Web API does. By default, Web API registers 'application/json' and 'text'json' but you can add your own media types by adding this to the WebApiConfig.Register method:

config.Formatters.JsonFormatter.SupportedMediaTypes.Add("application/vnd.api+json");

Hope this helps!

Henrik

dougbu commented 6 years ago

Closing as question has been answered.