Ejemplo n.º 1
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;
            foreach (var item in setting.Headers)
            {
                _request.Headers.Add(item);
            }
            _request.ContentType = setting.ContentType;
            _request.Timeout     = setting.Timeout;
            if (request != null)
            {
                SetRequsetCookie(null);
            }
        }
Ejemplo n.º 2
0
        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);
        }