简体   繁体   English

使用邮递员到 web api 2 c# 放置请求不起作用

[英]Put request is not working using postman to web api 2 c#

I have a method in Api as follows我在 Api 中有一个方法如下

[HttpPut]
        [Route("UpdateTeacher")]
        public IHttpActionResult UpdateTeacher(BusinessLayerTeacher Obj)
        {
            try
            {
                BusinessLayerTeacher obj = new BusinessLayerTeacher ();
                string status = BusinessLayerObject.UpdateTeacher(TeacherObj);
                return Ok(status);
            }
            catch
            {
                return NotFound();
            }
        }

Now in post man i am sending the put request to update the teacher object.现在在邮递员中,我正在发送 put 请求以更新教师对象。 It is not triggering this updateTeacher() method.它不会触发此 updateTeacher() 方法。

You are instantiating a new BusinessLayerTeacher object inside the method, which looks suspect when you are already passing in BusinessLayerTeacher as a parameter.您正在方法内部实例化一个新的 BusinessLayerTeacher 对象,当您已经将 BusinessLayerTeacher 作为参数传递时,该对象看起来很可疑。

Maybe the route mapping isn't working because you're not passing in the right data in the request body.也许路由映射不起作用,因为您没有在请求正文中传递正确的数据。

Maybe you should be using TeacherObj as the parameter type?也许您应该使用 TeacherObj 作为参数类型?

Have a review and give that a try, good luck :-)进行评论并尝试一下,祝你好运:-)

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

相关问题 对C#Web API的邮递员请求提供了空属性 - Postman request to C# Web API gives a null property 无法使用 c# 使用 Web 服务,但正在使用邮递员 - Unable to consume web services using c# but working on postman 尝试在本地C#web api中使用Postman PUT字符串,始终为null或失败 - Trying to PUT string with Postman in local C# web api, always null or fails 我有在天蓝色上烫过的网络API。 从邮递员那里得到请求,然后简单地得到请求。 但它不能从C#http get调用 - I have web api which is hoted on azure. get request working from postman and simple get request. But it not working from c# http get call Web API C#上具有多个参数的邮递员 - Postman with miltiple params on Web Api C# 将工作邮递员请求转换为 C# (HttpClient) - Convert Working Postman Request to C# (HttpClient) 使用HttpClient()在C#控制台应用程序中对REST API的PUT请求 - PUT Request for REST API in C# console application using HttpClient() c#使用Skydrive REST API进行PUT请求时遇到问题 - c# Trouble with PUT request using Skydrive REST API Post Rest Web API在Postman上工作,但未从C#项目中的代码返回任何响应 - Post rest web api working from Postman but not returning any response from code in C# project 无法从使用邮递员的网络API使用C#下载文件 - Not able to download file using C# from a web api which works using postman
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM