Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET核心Web API不支持的媒体类型_C#_Asp.net_Api - Fatal编程技术网

C# ASP.NET核心Web API不支持的媒体类型

C# ASP.NET核心Web API不支持的媒体类型,c#,asp.net,api,C#,Asp.net,Api,您好,我正在尝试使用ASP.net核心构建我的第一个API,并一直遵循本教程: 我想找出为什么我无法将任何内容发布到我的数据库(我在前面的步骤中设置了该数据库) 我用歌曲代替了todo,当我试图在postman中发出POST请求时,我得到了这个响应 { "type": "https://tools.ietf.org/html/rfc7231#section-6.5.13", "title": "Unsuppor

您好,我正在尝试使用ASP.net核心构建我的第一个API,并一直遵循本教程:

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

我用歌曲代替了todo,当我试图在postman中发出POST请求时,我得到了这个响应

{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.13",
    "title": "Unsupported Media Type",
    "status": 415,
    "traceId": "|25aa76f-4966fce03006b505."
}
无论我向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 { get; set; }
    }
这是指向我所处的确切步骤的链接:


另外,我在编程方面还是个新手,这可能是非常明显的事情。

是的,在《邮递员》中,我不得不将标题从text/plain更改为application/json


谢谢你的建议

是的,就是这样,在《邮差》中,我不得不将标题从text/plain更改为application/json


谢谢你的建议

在body请求中,您发送的JSON无效。您没有在标题中正确设置内容类型

要在POSTMAN中解决此问题,请单击文本并从下拉列表中选择JSON选项。然后添加打开和关闭的大括号。这样您就可以收到HTTP 400代码。像下面的代码片段一样发送对象

{ "FirstName":"Tom", "LastName":"Anderson", "Address":"Boston" } { “名字”:“汤姆”, “姓氏”:“安德森”, “地址”:“波士顿” }
在body请求中,您发送的JSON无效。您没有在标题中正确设置内容类型

要在POSTMAN中解决此问题,请单击文本并从下拉列表中选择JSON选项。然后添加打开和关闭的大括号。这样您就可以收到HTTP 400代码。像下面的代码片段一样发送对象

{ "FirstName":"Tom", "LastName":"Anderson", "Address":"Boston" } { “名字”:“汤姆”, “姓氏”:“安德森”, “地址”:“波士顿” }

错误表明您可能忘记了“将类型设置为JSON(应用程序/JSON)。@KirkLarkin谢谢,我现在已经设法解决了此问题。错误表明您可能忘记了“将类型设置为JSON(应用程序/JSON)。”@KirkLarkin谢谢,我现在已经设法解决了此问题