zoukankan      html  css  js  c++  java
  • C# 调用Restful 请求

    public static class HttpClientHelper
        {
            public static HttpClient GetXXXClient()
            {
                return GetHttpClient(ConfigurationManager.AppSettings["xxxxRESTService"]);
            }
    
            private static HttpClient GetHttpClient(string baseAddress)
            {
                var client = new HttpClient();
                string authenticationSchema = "xxxxxx";
                string tokenString = "xxxxx";
                string host = "xxxxxx";
    
                client.BaseAddress = new System.Uri(baseAddress);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add(authenticationSchema, tokenString);
                client.DefaultRequestHeaders.Host = host;
    
                return client;
            }
        }
    

      

            using (var client = HttpClientHelper.GetXXXXClient())
                {
                    string recordUrl = string.Format("record.json?app={0}&id=1", Utility.AppId);
                    var response = client.GetAsync(recordUrl).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        var employeeInfo = response.Content.ReadAsAsync<RecordInfo>().Result;
    
                        Console.WriteLine("test");
                    }
                }
    

      

     1         Record record = new Record();
     2             record.app = "182";
     3             Dictionary<string, FieldValue> dicFields = new Dictionary<string, FieldValue>();
     4             dicFields.Add("Id", new FieldValue() { value = "123" });
     5 
     6             using (var client = HttpClientHelper.GetKintoneClient())
     7             {
     8                 var response = client.PostAsync<object>("record.json", record, new JsonMediaTypeFormatter()).Result;
     9                 if (response.IsSuccessStatusCode)
    10                 {
    11                     var content = response.Content.ReadAsAsync<ResponseRecord>().Result;
    12                     if (content != null)
    13                     {
    14                         Console.WriteLine("success");
    15                     }
    16                 }
    17             }
  • 相关阅读:
    python操作word
    python安装pyautogui时遇到Pillow问题
    python中弹出消息框--MessageBox( pywin32)
    python 正则匹配汉字、简单读写、打开txt文件
    安装node(淘宝镜像)+Vue-cli+element-ui逐步搭建开发环境
    MT【317】两次判别式
    MT【316】常数变易法
    MT【315】勾股数
    MT【314】正切比值
    MT【313】特征方程逆用
  • 原文地址:https://www.cnblogs.com/KruceCoder/p/8040505.html
Copyright © 2011-2022 走看看