• asp.net post/get 公共方法


        public class HttpClientHelper
        {
            public static string Post(string url, string paramData)
            {
                return Post(url, paramData, Encoding.UTF8);
            }
    
            public static string Post(string url, string paramData, Encoding encoding)
            {
                string result = string.Empty ;
    
                if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1)
                {
                    ServicePointManager.ServerCertificateValidationCallback =
                                   new RemoteCertificateValidationCallback((sender, certificate, chain, errors) => { return true; });
                }
    
                try
                {
                    var wc = new WebClient();
                    if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
                        wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                    wc.Encoding = encoding;
    
                    result = wc.UploadString(url, "POST", paramData);
                }
                catch (Exception e)
                {
                    string ExceptContent = e.Message.ToString().Replace(""", "").Replace("'", "");
                    WeixinLog.WritExceptionLog("HttpClientHelper.Post", "url#" + url + "#paramData" + paramData);
                }
    
                return result;
            }
    
            public static string Get(string url)
            {
                return Get(url, Encoding.UTF8);
            }
    
            public static string Get(string url, Encoding encoding)
            {
                try
                {
                    var wc = new WebClient { Encoding = encoding };
                    var readStream = wc.OpenRead(url);
                    using (var sr = new StreamReader(readStream, encoding))
                    {
                        var result = sr.ReadToEnd();
                        return result;
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
  • 相关阅读:
    初识CC_MVPMatrix
    opengl启动过程
    http协议
    sockt套接字编程
    lua元表
    Codeforces 1203F1 Complete the Projects (easy version)
    CodeForces 1200E Compress Words
    CodeForces 1200D White Lines
    HDU 6656 Kejin Player
    HDU 6651 Final Exam
  • 原文地址:https://www.cnblogs.com/MichaelWillLee/p/6722496.html
Copyright © 2020-2023  润新知