I am creating an api conroller class in VB. I have a very simple function in it:
Public Function Post(<FromBody()> ByVal value As String) As String
Return value
End Function
When I send a POST request from HTTP Tool (FireFox extension), I can see it go in the function, but value
is always empty.
I have this in my WebApiConfig.vb
:
config.Routes.MapHttpRoute(
name:="Names",
routeTemplate:="{controller}/{id}",
defaults:=New With {.id = RouteParameter.Optional}
And this in Global.ASAX.vb
under Application-Start()
:
RouteTable.Routes.MapHttpRoute(name:="Post", routeTemplate:="post", defaults:=New With {.symbol = RouteParameter.Optional, .controller = "Names"})
I tried this from Fiddler 4 as well, but I get:
{"Message":"The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource.","ExceptionMessage":"No MediaTypeFormatter is available to read an object of type 'String' from content with media type 'application/octet-stream'.","ExceptionType":"System.Net.Http.UnsupportedMediaTypeException","StackTrace":" at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable '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)"}
Or when I try to set the content-type in the header I get:
No MediaTypeFormatter is available to read an object of type 'String' from content with media type ...
Where <...> is whatever media type I set.
How do I make this simple POST work?