简体   繁体   English

Web API C# POST

[英]Web api C# POST

I'm working on ASP net, and i have problem with post api.我在 ASP 网络上工作,但我在使用 post api 时遇到了问题。 I'm testing my api with postman, and have the Following message :我正在用邮递员测试我的 api,并收到以下消息:

在此处输入图片说明

Here is my code of POST verb :这是我的 POST 动词代码:

 // POST: api/Boooks
        [Route("~/api/PostCreate")]
        public IHttpActionResult Post([FromBody] Books books)
        {

            if (!ModelState.IsValid)
                return BadRequest("Invalid data.");


            // > (Variable)  Objet de connection PostGreSql qui va recevoir la connextion PostGre <
                Npgsql.NpgsqlConnection Psconnection;

            // > (Variable) Objet de connexion pour appel de la méthode 
            Sql_Connect_Data_Base ObjCnxDB = new Sql_Connect_Data_Base();

            // > On execute la connextion à la base et on recupert un objet connection <
            //   > On récupère l'objet de connexion dans "Psconnection" qui est retrourné par "ObjCnxDB.InitConnexionPostGres()" <
            Psconnection = ObjCnxDB.InitConnexionPostGres();


            // > Important : on doit respecter la casse dans les noms de colonnes <
            String ChnSqlInsert;
            // > Si le paramètre recçu est différent de nul <
            if (books != null)
                {
                ChnSqlInsert = books.ID;
                    }
            else 
            // > Object null ==> Eror message 
            {
                return BadRequest("Invalid data.");
            }

Change your ID_AUTO property in your Books class from int to string since your json shows that to be a string.Books类中的ID_AUTO属性从 int 更改为 string,因为您的 json 显示它是一个字符串。

Or you can change your value in postman to an int from string.或者,您可以将 postman 中的值更改为字符串中的 int。 Remove the quotes around 0 for ID_AUTO删除 ID_AUTO 的 0 周围的引号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM