Пример #1
0
 /// <summary>
 /// 添加请求头
 /// </summary>
 /// <param name="pair"></param>
 /// <returns></returns>
 public bool AddHeader(KeyValuePair <string, string> pair)
 {
     if (httpHeader == null)
     {
         return(false);
     }
     httpHeader.Add(pair);
     return(true);
 }
Пример #2
0
        /// <summary>
        /// 将HttpItem的请求头信息设置到指定Http请求头
        /// </summary>
        /// <param name="headers"></param>
        /// <param name="httpItem"></param>
        private void SetHeaders(HttpRequestHeaderCollection headers, HttpItem httpItem)
        {
            if (headers != null && httpItem != null)
            {
                if (!string.IsNullOrEmpty(httpItem.Accept))
                {
                    headers.Accept.TryParseAdd(httpItem.Accept);
                }

                if (!string.IsNullOrEmpty(httpItem.AcceptEncoding))
                {
                    headers.AcceptEncoding.TryParseAdd(httpItem.AcceptEncoding);
                }

                if (!string.IsNullOrEmpty(httpItem.AcceptLanguage))
                {
                    headers.AcceptLanguage.TryParseAdd(httpItem.AcceptLanguage);
                }

                //if (!string.IsNullOrEmpty(httpItem.ContentType))
                //{
                //    headers.Add("Content-Type", httpItem.ContentType);
                //}

                if (!string.IsNullOrEmpty(httpItem.Host))
                {
                    headers.Host = new HostName(httpItem.Host);
                }

                if (!string.IsNullOrEmpty(httpItem.Referer))
                {
                    headers.Referer = new Uri(httpItem.Referer);
                }

                if (!string.IsNullOrEmpty(httpItem.UserAgent))
                {
                    headers.UserAgent.TryParseAdd(httpItem.UserAgent);
                }

                if (httpItem.Header?.Count > 0)
                {
                    foreach (var item in httpItem.Header)
                    {
                        headers.Add(item.Key, item.Value);
                    }
                }
            }
        }
Пример #3
0
 public void UpdateSoapActionHeader(HttpRequestHeaderCollection headers)
 {
     headers.Clear();
     headers.Add("SOAPAction", SoapHeader);
 }