Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url">完整的url地址</param>
        public Url(string url)
        {
            if (url.IsNullOrWhiteSpace())
            {
                throw new BusinessException("url is not empty");
            }
            if (!url.StartsWith("http://") && !url.StartsWith("https://"))
            {
                throw new System.Exception("Please enter the correct url");
            }

            var uri = new Uri(url);

            Host         = uri.Host;
            Authority    = uri.Authority;
            Scheme       = uri.Scheme.ToLowers();
            IsHttps      = Scheme.Equals("https", StringComparison.CurrentCultureIgnoreCase);
            PathAndQuery = uri.PathAndQuery;
            Path         = PathAndQuery.Split('?').GetSafeString(0).Trim();
            RequestUrl   = url.Split('?').GetSafeString(0).Trim();
            if (url.Split('?').Length > 1)
            {
                UrlParameter = new UrlParameter(url.Split('?').GetSafeString(1).Trim());
            }
            else
            {
                UrlParameter = new UrlParameter();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 得到请求参数
 /// 格式:参数1=参数值&参数2=参数值
 /// </summary>
 /// <param name="isSort">是否排序</param>
 /// <param name="isUrlEncode">是否url编码</param>
 /// <param name="encoding">编码格式,默认UTF8</param>
 /// <returns></returns>
 public string GetQueryResult(bool isSort = false, bool isUrlEncode = false, Encoding encoding = null)
 {
     return(UrlParameter.GetQueryResult(isSort, isUrlEncode, encoding));
 }