Exemplo n.º 1
0
 /// <summary>
 /// 读取配置文件中该响应的报文编码方式
 /// </summary>
 /// <param name="responseUrl">响应请求的url</param>
 /// <returns>返回编码方式</returns>
 static Encoding LoadResponseEncoding(string responseUrl)
 {
     foreach (XmlElement ele in _httpCfg.SelectNodes("//Url"))
     {
         foreach (string UrlPrefix in ele.GetAttribute("prefix").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
         {
             if (!string.IsNullOrEmpty(UrlPrefix.TrimEnd('\r', '\n')) && responseUrl.StartsWith(UrlPrefix.TrimEnd('\r', '\n')))
             {
                 XmlNode Encoding = ele.SelectSingleNode("ResponseEncoding");
                 if (Encoding != null)
                 {
                     return(System.Text.Encoding.GetEncoding(Encoding.InnerText));
                 }
             }
         }
     }
     return(Encoding.UTF8);
 }
Exemplo n.º 2
0
 /// <summary>
 /// 读取配置文件中该soap请求的消息头
 /// </summary>
 /// <param name="requestUrl">请求url</param>
 /// <returns>返回该请求的url的soap消息头</returns>
 static string LoadSoapHeader(this string requestUrl)
 {
     foreach (XmlElement ele in _httpCfg.SelectNodes("//Url"))
     {
         foreach (string UrlPrefix in ele.GetAttribute("prefix").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
         {
             if (!string.IsNullOrEmpty(UrlPrefix.TrimEnd('\r', '\n')) && requestUrl.StartsWith(UrlPrefix.TrimEnd('\r', '\n')))
             {
                 XmlNode soapHeader = ele.SelectSingleNode("SoapHeader");
                 if (soapHeader != null)
                 {
                     return(soapHeader.InnerText);
                 }
             }
         }
     }
     return("");
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a remote url from a remote request
 /// </summary>
 /// <param name="context">The request context.</param>
 protected virtual string BuildUrl(IHttpContext context)
 {
     return(UrlPrefix.TrimEnd('/') + '/' + context.Request.Path.TrimStart('/'));
 }
Exemplo n.º 4
0
 /// <summary>
 /// 根据url匹配项,加载自定义配置。
 /// </summary>
 /// <param name="req"></param>
 /// <param name="RequestUrl"></param>
 /// <returns></returns>
 static HttpWebRequest LoadConfig(this HttpWebRequest req, string RequestUrl)
 {
     foreach (XmlElement ele in _httpCfg.SelectNodes("//Url"))
     {
         foreach (string UrlPrefix in ele.GetAttribute("prefix").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
         {
             if (RequestUrl.StartsWith(UrlPrefix.TrimEnd('\r', '\n')) && !string.IsNullOrEmpty(UrlPrefix.TrimEnd('\r', '\n')))
             {
                 XmlNode ContentType = ele.SelectSingleNode("ContentType");
                 if (ContentType != null)
                 {
                     req.ContentType = ContentType.InnerText;
                 }
                 XmlNode Authorization = ele.SelectSingleNode("Authorization");
                 if (Authorization != null)
                 {
                     req.Headers.Set(HttpRequestHeader.Authorization, Authorization.InnerText);
                 }
                 XmlNode UserAgent = ele.SelectSingleNode("UserAgent");
                 if (UserAgent != null)
                 {
                     req.UserAgent = UserAgent.InnerText;
                 }
                 XmlNode Accept = ele.SelectSingleNode("Accept");
                 if (Accept != null)
                 {
                     req.Accept = Accept.InnerText;
                 }
                 XmlNode Pragma = ele.SelectSingleNode("Pragma");
                 if (Pragma != null)
                 {
                     req.Headers.Set(HttpRequestHeader.Pragma, Pragma.InnerText);
                 }
                 XmlNode Origin = ele.SelectSingleNode("Origin");
                 if (Origin != null)
                 {
                     req.Headers.Set("Origin", Origin.InnerText);
                 }
                 XmlNode Referer = ele.SelectSingleNode("Referer");
                 if (Referer != null)
                 {
                     req.Referer = Referer.InnerText;
                 }
                 XmlNode Connection = ele.SelectSingleNode("Connection");
                 if (Connection != null)
                 {
                     SetHeaderValue(req.Headers, "Connection", Connection.InnerText);
                 }
                 XmlNode AcceptEncoding = ele.SelectSingleNode("AcceptEncoding");
                 if (AcceptEncoding != null)
                 {
                     req.Headers.Set(HttpRequestHeader.AcceptEncoding, AcceptEncoding.InnerText);
                 }
                 XmlNode AcceptLanguage = ele.SelectSingleNode("AcceptLanguage");
                 if (AcceptLanguage != null)
                 {
                     req.Headers.Set(HttpRequestHeader.AcceptLanguage, AcceptLanguage.InnerText);
                 }
                 XmlNode SOAPAction = ele.SelectSingleNode("SOAPAction");
                 if (SOAPAction != null)
                 {
                     req.Headers.Set("SOAPAction", SOAPAction.InnerText);
                 }
                 XmlNode KeepAlive = ele.SelectSingleNode("KeepAlive");
                 if (KeepAlive != null)
                 {
                     req.KeepAlive = KeepAlive.InnerText.Trim() == "true";
                 }
                 XmlNode AllowAutoRedirect = ele.SelectSingleNode("AllowAutoRedirect");
                 if (AllowAutoRedirect != null)
                 {
                     req.AllowAutoRedirect = AllowAutoRedirect.InnerText.Trim() == "true";
                 }
             }
         }
     }
     return(req);
 }