A vendor API I need to use is sending a POST request with content-type: text/plain and JSON in the body.
How do I parse it in .net core 1.0 web api?
I'm sure I need to do something similar to this (code below) answer, but I don't know how in web api.
public class RawContentTypeMapper : WebContentTypeMapper
{
public override WebContentFormat GetMessageFormatForContentType(string contentType)
{
switch (contentType.ToLowerInvariant())
{
case "text/plain":
case "application/json":
return WebContentFormat.Json;
case "application/xml":
return WebContentFormat.Xml;
default:
return WebContentFormat.Default;
}
}
}
I made it work by adding the
text/plain
content-type to theJsonInputFormatter
inStartup.cs
ConfigureServices()
method, like so:Edit: I made a seed project for the SNS client lambda, that parses the message and confirms the subscription out the box.