refit
refit copied to clipboard
[BUG] Content-Type of Header causes a 415 error in WebAPI
Describe the bug
I have a WebAPI function as follows.
-
LoginController.cs
[HttpPost]
public Login Post([FromBody] string token)
{
...
}
-
BaseAPI.cs
[Post("/api/login")]
Task<Login> Login([Body] string token);
I found that "HTTP 415 Unsupported Media Type" keeps appearing when sending data. Then when I checked the sent data, I found that the "Content-Type" is "text/plain; charset=UTF-8". However, the WebAPI in dot NET 6 only accepts "application/json" data, so I tried to modify the header, but I found that no matter how I modify it, there is an extra paragraph "text/plain; charset=UTF-8" in front of it.
Steps To Reproduce
Expected behavior
Screenshots
Environment
- Blazor .NET 6 PWA
- Edge 99.0.1150.11 beta x64
Additional context
I am experiencing this as well when trying to POST SOAP XML to an endpoint.
Resulting header: Content-Type: text/plain; charset=utf-8, application/soap+xml; charset=utf-8
Interface:
[Headers("Content-type: application/soap+xml; charset=utf-8")]
public interface ISOAPAPI
{
[Post("/service.asmx")]
Task PostDocument([Body] string xmlDocument);
}
This exists in 6.3.2 and 6.2.16. I will keep trying other versions.
@bestpika I got mine to work by changing the Headers
to be:
[Headers("Content-Type: application/soap+xml; charset=utf-8")]
Specifically, Content-Type
with a capital C and T.
This would be the kind of thing it would be handy to have a Roslyn Analyzer for...