Exemplo n.º 1
0
        /// <summary>
        /// 获取Url参数
        /// </summary>
        /// <param name="setting"></param>
        /// <returns></returns>
        protected virtual string GetQueryString(RequestSetting setting)
        {
            string result = string.Empty;

            if (setting.UriParameters != null && setting.UriParameters.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("?");
                foreach (var item in setting.UriParameters)
                {
                    sb.AppendFormat("{0}={1}&", item.Key, item.Value);
                }
                result = sb.ToString();
                result = result.Substring(0, result.Length - 1);
            }
            return(result);
        }
Exemplo n.º 2
0
        public RestRequest(RequestSetting setting)
        {
            Setting = setting;
            var        queryString = GetQueryString(setting);
            UriBuilder ub          = new UriBuilder(setting.Schema, setting.Host, setting.Port, setting.Path, queryString);

            Uri = ub.Uri;
            if (Uri.Scheme.ToLower() == "https")
            {
                ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidate;
            }
            _request             = WebRequest.Create(Uri);
            request              = _request as HttpWebRequest;
            _request.Method      = setting.Method;
            _request.ContentType = setting.ContentType;
            _request.Timeout     = setting.Timeout;
            request.Accept       = "*/*";
            request.UserAgent    = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0;)";
            SetHeaders(setting.Headers);
            if (request != null)
            {
                SetRequsetCookie(null);
            }
        }