• 调用WebAPI接口


       [HttpPost]          接口
    public string Post([FromBody] string bjbh)        
    {           

              var dwgc = new object();     

               string output = string.Empty;  

               string msg = string.Empty;

                bool result = true;

                string errorCode = "200";

                try            

               {               

                    var dwgcbybjbhlist = db.Base_GetDwgcxxByBjbh(bjbh);                

                  dwgc = new                    

                     {                      

                     page = pageIndex,      

                     total = dwgcbybjbhlist.Count()%pageSize==0 ? dwgcbybjbhlist.Count()/pageSize : dwgcbybjbhlist.Count()/pageSize + 1,                records = dwgcbybjbhlist.Count(),    

                     dwgcxx =dwgcbybjbhlist//.OrderBy(x => x.bjbh).Skip(pageSize*(pageIndex - 1)).Take(pageSize).ToList(),                     };                }            

               catch (Exception ex)            

                {                

                 result = false;    

                 msg = ex.Message;           

                  errorCode = "300";          

               }   

              finally     

             {                

                   var dwgcJson = new                

                   {                    

                      Result = result, //执行正常返回true,异常返回false                    

                      ErrorCode = errorCode, //错误编号信息

                        Message = msg, //执行情况说明   

                      Data = dwgc, //合同信息

                    };               

                 output = Newtonsoft.Json.JsonConvert.SerializeObject(dwgcJson);         

            }            

             return output;      

      }

    调用
     private string WebAPITest()
            {
                string postString = "=3333333";
                byte[] postData = System.Text.Encoding.UTF8.GetBytes(postString); //编码,尤其是汉字,事先要看下抓取网页的编码方式 
                var client = new WebClient();
                client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                client.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");//采取POST方式必须加的header,如果改为GET方式的话就去掉这句话即可 
                string newUrl = "http://localhost/XMSGXKZService/v1/GetDwgcByBjbh";
                byte[] responseData = client.UploadData(newUrl, "POST", postData); //得到返回字符流 
                string value1 = Encoding.UTF8.GetString(responseData);
                return value1;
            }

  • 相关阅读:
    邻接矩阵有向图的介绍
    Oracle库Delete删除千万以上普通堆表数据的方法
    Oracle 11g静默安装软件+手工创建数据库
    Oracle基础维护02-表、主键、索引、表结构维护手册
    批处理:Windows主机通过FTP下载远程Linux主机上文件
    Vertica license导入最佳实践
    各类数据库问题描述模板
    Oracle同义词+dblink的实际应用
    Oracle数据逻辑迁移综合实战篇
    Greenplum 数据库安装部署(生产环境)
  • 原文地址:https://www.cnblogs.com/hui721/p/4203359.html
Copyright © 2020-2023  润新知