webApi of FromUri and FromBody difference

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" );
    }

 

  Class definitions 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 here mandatory reading FileRequest object from the url, ie

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

   Here the parameters are automatically converted Uri the form as an object property passed to ignore data

 

FromBody forces used to read data from the FormData

Rather than get the URL parameters ~

Guess you like

Origin www.cnblogs.com/Jeely/p/10958807.html