示例#1
0
        /// <summary>
        /// Create a new request
        /// </summary>
        public static RequestFluent Create(string url)
        {
            RequestFluent result;

            // if we got a valid url
            if (HelperUrl.IsUrlValid(url))
            {
                // create a request
                result = new RequestFluent(url);
            }
            // if url is not valid
            else
            {
                // then we have a problem
                throw new ArgumentException(string.Format("Invalid uri '{0}'", url));
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Create a new request
        /// </summary>
        public RequestFluent CreateRequest(string url)
        {
            RequestFluent result;

            // if we got a valid url
            if (HelperUrl.IsUrlValid(url))
            {
                // if we have a parameters
                if ((this._urlParameters != null) &&
                    (this._urlParameters.Count > 0))
                {
                    // loop
                    foreach (var urlParameter in this._urlParameters)
                    {
                        // update
                        url = HelperUrl.SetParameter(url, urlParameter.Key, urlParameter.Value);
                    }
                }
                // create a request
                result = RequestFluent.Create(url);

                // if configured
                if (this._contentType != null)
                {
                    // update the request
                    result.ContentType(this._contentType);
                }

                // if configured
                if (this._encoding != null)
                {
                    // update the request
                    result.Encoding(this._encoding);
                }

                // if configured
                if (this._allowAutoRedirect.HasValue)
                {
                    // update the request
                    result.AllowAutoRedirect(this._allowAutoRedirect.Value);
                }

                // if configured
                if (this._accept != null)
                {
                    // update the request
                    result.Accept(this._accept);
                }

                // if configured
                if (this._userAgent != null)
                {
                    // update the request
                    result.UserAgent(this._userAgent);
                }

                // if any header
                if ((this._headers != null) &&
                    (this._headers.Count > 0))
                {
                    // loop
                    foreach (var header in this._headers)
                    {
                        result.Header(header.Key, header.Value);
                    }
                }
            }
            // if url is not valid
            else
            {
                // then we have a problem
                throw new ArgumentException(string.Format("Invalid uri '{0}'", url));
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// Add a querystring parameter in the request URL
        /// </summary>
        public RequestFluent AddUrlParameter(string parameter, object value)
        {
            this._url = HelperUrl.AddParameter(this._url, parameter, value);

            return(this);
        }