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

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

ublic 
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类的定义

1
2
3
4
5
6
7
public 
class 
FileRequest
 
{
     
public 
string 
name { 
get
set
; }
 
     
public 
string 
SelectedItemId { 
get
set
; }
     
public 
IEnumerable<SelectListItem> Items { 
get
set
; }
 
}

  

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

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

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

 

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

而非URL中获取参数~

转载于:https://www.cnblogs.com/Jeely/p/10958807.html

你可能感兴趣的文章
ES6中变量的解构赋值
查看>>
编译器C-Free V352注册算法分析
查看>>
数据绑定控件Reperter
查看>>
【codeforces】【比赛题解】#937 CF Round #467 (Div. 2)
查看>>
剑指Offer学习笔记(3)——解决面试题的思路
查看>>
.NET Framework基础知识(二)(转载)
查看>>
Yii DataProvider
查看>>
BestCoder Round #14 B 称号 Harry And Dig Machine 【TSP】
查看>>
hdu 1114 Piggy-Bank
查看>>
maven集成tomcat插件启动报错
查看>>
Boost库编译安装
查看>>
Python matplot画散列图
查看>>
C#/.NET整数的三种强制类型转换(int)、Convert.ToInt32()、int.Parse()的区别
查看>>
算法复习——数位dp(不要62HUD2089)
查看>>
PhpSpreadsheet如何读取excel文件
查看>>
如何选购一款好的人事档案管理系统
查看>>
Spark2.1.0——运行环境准备
查看>>
[转载]C#异步调用四大方法详解
查看>>
在windows下添加php的Imagick扩展
查看>>
python3 爬取百合网的女人们和男人们
查看>>