获得WebApi用Post方法获得新增数据的信息
2024-09-04 15:27:30
首先,要知道webApi的基本返回方式是HttpResponseMessage,post会在响应中返回添加的对象,以及添加对象的访问地址
如:在fiddler里测试的时候
然后,我们可以根据这一点在后台方法中进行操作,在添加方法中获得刚加入的数据。
//添加操作
ProductService.AddProduct(product);
//获得添加的响应
var response = Request.CreateResponse<Product>(HttpStatusCode.Created, product);
//获得访问地址
string uri = Url.Link("DefaultApi", new { id = product.ProductID });
//获得刚添加数据的id
int id = product.ProductID;
注:仅为个人理解与笔记,有错误的地方请指正O(∩_∩)O!
最新文章
- PHP获得两个绝对路径的相对路径
- ORACLE 语句关联统计
- 高性能CSS(二)
- mysql insert语句错误问题解决
- MVC中不能使用原生态的#include ,可替代的解决方案
- silverlight visifire控件图表制作——silverlight 后台方法打印
- OpenSSl 加密解密 示例(终于有编程实践了)
- VS2012添加对DirectX SDK中需要文件的引用
- [Hadoop] - 自定义Mapreduce InputFormat&;OutputFormat
- vue 实现 换一换 功能
- python+eclipse+pydev开发环境搭建
- 计算机网络之套接字SOCKET
- Python生成器的原理及使用
- IDEA cannot resolve symbol “xxxx”
- Linux 自动化部署Rsyslog服务
- 使用nvm安装node,全局npm,cnpm
- SparkSQL demo
- Oracle数据库查看SID和service_name
- Java设计模式应用——桥接模式
- 【mysql】测试方案整理
热门文章
- Notes of the scrum meeting(12.10)
- 20172314 Android程序设计 实验四
- 团队第一次作业 ——404 Note Found 团队
- Windows 7中安装Solr7
- yum 安装 redis php-redis
- python redis插件安装
- 数据存储到MySQL并返回新插入的id值
- 【转】关于增量链接(incremental linking)
- Redis 学习之主从复制
- java.awt.AWTError: Can&#39;t connect to X11 window server using &#39;:20&#39; as the value of the DISPLAY variable