Beispiel #1
0
        /// <summary>
        /// Get raw response from type
        /// </summary>
        /// <param name="token">Token to be passed</param>
        /// <param name="url">Url to be hit to delete</param>
        /// <param name="type">Http type, post, put, delete</param>
        /// <param name="content">content to be put in case of put, post</param>
        /// <returns></returns>
        public static string GetRawResponse(string token, string url, HttpTypeEnum type, StringContent content = null)
        {
            var jsonContent = string.Empty;

            using (var client = GetClient(token))
            {
                var response = new HttpResponseMessage();
                if (type == HttpTypeEnum.Delete)
                {
                    response = client.DeleteAsync(url).Result;
                }
                else if (type == HttpTypeEnum.Post)
                {
                    response = client.PostAsync(url, content).Result;
                }
                else if (type == HttpTypeEnum.Put)
                {
                    response = client.PutAsync(url, content).Result;
                }

                if (response.IsSuccessStatusCode)
                {
                    jsonContent = response.Content.ReadAsStringAsync().Result;
                    response.Dispose();
                }

                return(jsonContent);
            }
        }
Beispiel #2
0
 /// <summary>
 /// 重载ToHttpUrl,默认url:Request.Url.AbsoluteUri
 /// </summary>
 public static string ToHttpUrl(HttpTypeEnum httpType = HttpTypeEnum.Http)
 {
     if (null == HttpContext.Current)
     {
         return(string.Empty);
     }
     return(ToHttpUrl(HttpContext.Current.Request.Url.AbsoluteUri, httpType));
 }
Beispiel #3
0
 /// <summary>
 /// 将http开头协议不规则的url字符串转化为指定的http://或https://形式的url
 /// </summary>
 /// <param name="url">要转换的url</param>
 /// <param name="httpType">http类型,默认为http://</param>
 /// <returns>转换后的url</returns>
 public static string ToHttpUrl(string url, HttpTypeEnum httpType = HttpTypeEnum.Http)
 {
     if (string.IsNullOrWhiteSpace(url))
     {
         return(string.Empty);
     }
     url = url.Trim().TrimStart(new char[] { ':', '/' });
     url = XCLNetTools.Common.Consts.RegHttpScheme.Replace(url, string.Empty);
     return(string.Format("{0}://{1}", httpType.ToString().ToLower(), url));
 }
Beispiel #4
0
 /// <summary>
 /// 将网站根Uri转为开头带http://或https://的url地址
 /// 如:"http://www.xcl.com:2156/ or https://www.xcl.com:2156/VirtualWeb/"
 /// </summary>
 /// <param name="httpType">http类型,默认为http://</param>
 /// <returns>处理后的url</returns>
 public static string GetRootUri(HttpTypeEnum httpType = HttpTypeEnum.Http)
 {
     return(Common.ToHttpUrl(Common.RootUri, httpType));
 }