zoukankan      html  css  js  c++  java
  • HttpClient Post示例

     var url = "http://11.4.64.77:8888/a/b";
                if (url.StartsWith("https"))
                    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
    
                foreach (var item in replyList)
                {
                    try
                    {
                        HttpContent httpContent = new StringContent(JsonUtil.Stringify(new
                        {
                            flightId = item.FlightId,
                            userId = user.Id,
                            etd = item.ReplyStd,
                            isEtdNotice = item.Notice
                        }));
                        httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                        httpContent.Headers.Add("APIKey", "jjj");
                        HttpClient httpClient = new HttpClient();
    
                        HttpResponseMessage response = httpClient.PostAsync(url, httpContent).Result;
    
                        if (response.IsSuccessStatusCode)
                        {
                            string result = response.Content.ReadAsStringAsync().Result;
                            item.SendFail = !(result != null && result.Contains("OK"));
                        }
                    }
                    catch (Exception)
                    {
                        item.SendFail = true;
                    }
    

      

  • 相关阅读:
    Codeforces-541div2
    动态规划-线性dp-hdu-4055
    动态规划_线性dp
    动态规划_背包问题笔记
    codeforces-1111
    数论模板
    codeforces-1114F-线段树练习
    2-sat
    拓扑排序
    强连通分量
  • 原文地址:https://www.cnblogs.com/saving/p/13821171.html
Copyright © 2011-2022 走看看