博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
webApi之FromUri和FromBody区别
阅读量:4553 次
发布时间:2019-06-08

本文共 1287 字,大约阅读时间需要 4 分钟。

    public Link GetLink([FromUri] FileRequest fileRequest)        {            if (ModelState.IsValid)            {                var xml = WebConfigurationManager.AppSettings["appDiscoveryXml"];                var wopiServer = WebConfigurationManager.AppSettings["appWopiServer"];                bool updateEnabled = false;                bool.TryParse(WebConfigurationManager.AppSettings["updateEnabled"], out updateEnabled);                WopiAppHelper wopiHelper = new WopiAppHelper(HostingEnvironment.MapPath(xml), updateEnabled);                var result = wopiHelper.GetDocumentLink(wopiServer + fileRequest.name);                var rv = new Link                {                    Url = result                };                return rv;            }            throw new ApplicationException("Invalid ModelState");        }

 

  FileRequest类的定义

  public class FileRequest    {        public string name { get; set; }        public string SelectedItemId { get; set; }        public IEnumerable
Items { get; set; } }

  

 这里的FromUri强制从url中读取FileRequest 对象,也就是说

    当访问Http://localhost:80?name=eric&SelectedItemId={Guid.NewGuid()}

   此处将自动转换Uri中的参数作为对象属性忽略form传递的数据

 

而使用FromBody将强制从FormData中读取数据

而非URL中获取参数~

 

转载于:https://www.cnblogs.com/anbylau2130/p/4860470.html

你可能感兴趣的文章
nodejs概述
查看>>
H3C PAP验证配置示例
查看>>
oracle-Dbca数据库模板
查看>>
ionic 轮播
查看>>
Faster-RCNN Pytorch实现的minibatch包装
查看>>
[LeetCode] 168. Excel Sheet Column Title_Easy tag: Math
查看>>
[Ionic] Build and Run an Ionic App from Scratch
查看>>
纯手写wcf代码,wcf入门,wcf基础教程
查看>>
关于8.0.15版本的mysql下载与安装
查看>>
Redis主从复制看这篇就够了
查看>>
部署和调优 2.3 tomcat中JDK安装
查看>>
洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth 题解
查看>>
(4.20)SQL Server数据库启动过程,以及启动不起来的各种问题的分析及解决技巧...
查看>>
基本数据类型(数字和字符串)
查看>>
函数__装饰器
查看>>
linux system函数分析
查看>>
前端优化措施
查看>>
论学习汉语和学习编程的异同点
查看>>
linux img文件压缩及解压
查看>>
计算php脚本执行时间
查看>>