小编Tie*_*ske的帖子

ASP.NET Core Web API 不支持的媒体类型

您好,我正在尝试使用 ASP.net Core 构建我的第一个 API,并一直在遵循本教程:https ://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view= aspnetcore-3.1&tabs=visual-studio

我想知道为什么我无法将任何内容发布到我的数据库(我在前面的步骤中已设置)

我使用歌曲而不是待办事项,当我尝试在邮递员中发出 POST 请求时,我收到此响应

{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.13",
    "title": "Unsupported Media Type",
    "status": 415,
    "traceId": "|25aa76f-4966fce03006b505."
}
Run Code Online (Sandbox Code Playgroud)

无论我发送到 API 的键:值对是什么,使用 post 方法时我总是会得到相同的响应。

我的歌曲类如下所示:

    public class Song
    {
        public int Id { get; set; }

        public string Title { get; set; }

        public string Artist { get; set; }

        [DataType(DataType.Date)]
        public DateTime ReleaseDate { get; set; }

        public string Spotify { get; set; }

        public string Youtube { get; set; }

        public string Instagram …
Run Code Online (Sandbox Code Playgroud)

c# asp.net api

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

api ×1

asp.net ×1

c# ×1