Anfragen an Controller mit Umlauten (Sonderzeichen) funktionieren nicht mit BodyC#

Ein Treffpunkt für C#-Programmierer
Guest
 Anfragen an Controller mit Umlauten (Sonderzeichen) funktionieren nicht mit Body

Post by Guest »

Angesichts des folgenden Controllers (erstellt mit Visual Studio 15.8.2 → WebApi-Vorlage):

[Route("api/[controller]")]
[ApiController]
public class StädteController : ControllerBase
{
private static readonly List Städte = new List{"Berlin","Hamburg","München","Köln","Frankfurt","Stuttgart","Düsseldorf","Dortmund","Essen"};

// GET api/Städte
[HttpGet]
public ActionResult Get()
{
return Städte;
}

// Post api/Städte/Leipzig
[HttpPost("{id}")]
public void Post(string id)
{
if (!Städte.Contains(id))
Städte.Add(id);
}

// Post api/Städte
[HttpPost]
public void Post([FromBody] IEnumerable städte)
{
Städte.AddRange(städte?.Except(Städte) ?? Enumerable.Empty());
}
}


Jede Anfrage ohne Nutzlast funktioniert (OK 200 wird zurückgegeben):
Anfragen mit einem Textkörper funktionieren nicht (NOT FOUND 404 wird zurückgegeben):
Die Verwendung von PUT führt zu einem äquivalenten Ergebnis! ä in ae umzubenennen wird funktionieren, aber ich mag es nicht!

Weiß jemand, warum das Routing unterbrochen wird, wenn ein Körper vom Controller erwartet wird? Aktion? Was ist die beste Lösung, um dem Kunden URIs mit Umlauten anzubieten?



ASP.NET Core-Webserverprotokoll:

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 POST http://localhost:44301/api/St��dte application/json 23
trce: Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware[0]
All hosts are allowed.
dbug: Microsoft.AspNetCore.Builder.RouterMiddleware[1]
Request did not match any routes.
dbug: Microsoft.AspNetCore.Server.Kestrel[9]
Connection id "0HLGJ46FC5IM0" completed keep alive response.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 11.5071ms 404
dbug: Microsoft.AspNetCore.Server.Kestrel[25]
Connection id "0HLGJ46FC5IM0", Request id "0HLGJ46FC5IM0:00000002": started reading request body.
dbug: Microsoft.AspNetCore.Server.Kestrel[26]
Connection id "0HLGJ46FC5IM0", Request id "0HLGJ46FC5IM0:00000002": done reading request body.
info: Microsoft.AspNetCore.Server.Kestrel[32]
Connection id "0HLGJ46FC5IM0", Request id "0HLGJ46FC5IM0:00000002": the application completed without reading the entire request body.




UPDATE 27.06.2019:

ASP .NET Core 2.2:
  • POST funktioniert jetzt
    GET funktioniert nicht :-(
https://github.com/aspnet/AspNetCore/issues/11640

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post