Beispiel #1
0
        //private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        //{
        //    Debug.WriteLine("accept name = "+ certificate.GetName());
        //    return true;
        //}

        /// <summary> 设置请求头相关信息 </summary>
        /// <param name="request"></param>
        /// <param name="param">  </param>
        public static void SetHttpWebRequestHeaders(HttpWebRequest request, HttpTaskParams param)
        {
            if (request == null || param == null)
            {
                return;
            }

            request.Method = ConvertHttpWebRequestMethodString(param.Method);
            request.Headers.Add("Charset", "UTF-8");
            if (string.IsNullOrEmpty(param.ContentType))
            {
                if (!param.HasFileParams() && param.Method == HttpTaskParams.METHOD_POST)
                {
                    request.ContentType = "application/x-www-form-urlencoded";
                }
            }
            else
            {
                request.ContentType = param.ContentType;
            }
        }