如何在WebApI中使用HTTp POST方法接收多个复杂对象 [英] How to receive multiple complex objects using HTTp POST method in WebApI

查看:690
本文介绍了如何在WebApI中使用HTTp POST方法接收多个复杂对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想调用一个WebApi方法,这就是我的webapi方法的样子:





Hi,
I want to call an WebApi Method,this is how my webapi method looks like:


[HttpPost]
            [Route("PostMyService/updatedBy/{updatedByID}/myobjname")]
            public void PostTerminalService([FromBody]  List<SomeType> lstSomeObj, MyClass myobj, int updatedByID)
    {
    //Do Something
    }





这是怎么回事我的客户看起来像:





this is how my client looks like:

int loggedinuserid=1;
     List<Sometype> liTS = new List<SomeType>();
   MyClass myobj=new MyClass();
       var url = "api/XYZ/PostMyService/updatedBy/" + loggedinuserid + "/myobjname/" + myobj;
       HttpResponseMessage response = client1.PostAsJsonAsync(url, liTS).Result;





但我得到的错误/异常是:

HTTP错误404.0 - 未找到

最有可能的原因:

•Web服务器上不存在指定的目录或文件。

•URL包含打字错误。

•自定义过滤器或模块(如URLScan)限制对文件的访问。




任意想法如何解决这个问题?我在这方面遇到了障碍。



提前感谢。



But the error/exception I am getting is:
HTTP Error 404.0 - Not Found
Most likely causes:
•The directory or file specified does not exist on the Web server.
•The URL contains a typographical error.
•A custom filter or module, such as URLScan, restricts access to the file.


Any idea how to resolve this?I am kind of hitting a wall on this.

thanks in advance.

推荐答案

用这个更新你的api方法

Update your api method with this
[Route("PostMyService/updatedBy/{updatedByID:int}/myobjname/{myobj:MyClass }")]
   public List<sometype> PostTerminalService(int updatedByID,MyClass myobj)
    {
    //Do Something
    }


这篇关于如何在WebApI中使用HTTp POST方法接收多个复杂对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆