zoukankan      html  css  js  c++  java
  • HttpClient请求发送的几种用法二:

    public class HttpClientHelper
        {
            private static readonly HttpClientHelper _instance = new HttpClientHelper();
            private readonly HttpClient Client = new HttpClient();
            private HttpClientHelper()
            {
               // Client.BaseAddress =new Uri(Options.ServerUrl);
            }

            public static HttpClientHelper Instance
            {
                get { return _instance; }
            }

            public string Post(string processor, Dictionary<string, string> paras)
            {
                var req = new HttpRequestMessage();
                req.Headers.Clear();
                if (processor.Contains("smsGBK.aspx"))
                {
                    //req.Encoding = Encoding.GetEncoding("GBK");
                    req.Headers.Add("Content-Type", "application/x-www-form-urlencoded;charset=GB2312");
                }
                req.Headers.Add("ContentType", "application/x-www-form-urlencoded;charset=utf-8");
                req.Method = HttpMethod.Post;
                req.Content = new FormUrlEncodedContent(paras);
                req.RequestUri = new Uri(Options.ServerUrl+processor);
                var response = Client.SendAsync(req).Result;
                try
                {
                    response.EnsureSuccessStatusCode();
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Error:{0}", ex.Message);
                    return "";
                }
                return response.Content.ReadAsStringAsync().Result;
            }
        }

  • 相关阅读:
    学习html5 中的canvas(一)
    js中的width问题
    css3中我们不知道的一些属性
    css3的渐变效果
    校园商铺-6店铺编辑列表和列表功能-1店铺信息编辑之Dao层开发
    校园商铺-4店铺注册功能模块-14前后端联调技巧细化与总结
    校园商铺-4店铺注册功能模块-13前后端联调验证整体模块功能
    校园商铺-4店铺注册功能模块-12引入kaptcha实现验证码
    11-接下来如何做
    10-K最近邻算法
  • 原文地址:https://www.cnblogs.com/rengke2002/p/6964085.html
Copyright © 2011-2022 走看看