[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):
- GET https://localhost:44301/api/Städte
- GET https://localhost:44301/api/St%C3%A4dte
- POST https://localhost:44301/api/Städte/Leipzig
- POST https://localhost:44301/api/St%C3%A4dte/Leipzig
- POST https://localhost:44301/api/Städte
["Dresden", "Chemnitz"] - POST https://localhost:44301/api/St%C3%A4dte
["Dresden", "Chemnitz"]
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