/// <summary>
        /// Creates the Redmine web client.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        /// <code></code>
        protected WebClient CreateUploadWebClient(NameValueCollection parameters = null)
        {
            var webClient = new RedmineWebClient();

            if (parameters != null)
            {
                webClient.QueryString = parameters;
            }

            if (!string.IsNullOrEmpty(apiKey))
            {
                webClient.QueryString["key"] = apiKey;
            }
            else
            {
                if (cache != null)
                {
                    webClient.Credentials = cache;
                }
            }

            webClient.UseDefaultCredentials = false;

            webClient.Headers.Add("Content-Type", "application/octet-stream");
            // Workaround - it seems that WebClient doesn't send credentials in each POST request
            webClient.Headers.Add("Authorization", basicAuthorization);

            return(webClient);
        }
        /// <summary>
        /// Creates the Redmine web client.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        /// <code></code>
        protected WebClient CreateWebClient(NameValueCollection parameters)
        {
            var webClient = new RedmineWebClient();

            if (parameters != null)
            {
                webClient.QueryString = parameters;
            }

            if (!string.IsNullOrEmpty(apiKey))
            {
                webClient.QueryString["key"] = apiKey;
            }
            else
            {
                if (cache != null)
                {
                    webClient.Credentials = cache;
                }
            }

            if (!string.IsNullOrWhiteSpace(ImpersonateUser))
            {
                webClient.Headers.Add("X-Redmine-Switch-User", ImpersonateUser);
            }

            webClient.Headers.Add("Content-Type", mimeFormat == MimeFormat.json ? "application/json; charset=utf-8" : "application/xml; charset=utf-8");
            webClient.Encoding = Encoding.UTF8;
            return(webClient);
        }
Пример #3
0
        /// <summary>
        /// Creates the Redmine web client.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        /// <code></code>
        protected WebClient CreateWebClient(NameValueCollection parameters)
        {
            var webClient = new RedmineWebClient();

            webClient.Headers.Add(HttpRequestHeader.ContentType, mimeFormat == MimeFormat.json ? "application/json" : "application/xml");
            webClient.Encoding = Encoding.UTF8;

            if (parameters != null)
            {
                webClient.QueryString = parameters;
            }

            if (!string.IsNullOrEmpty(apiKey))
            {
                webClient.QueryString["key"] = apiKey;
            }
            else
            {
                // if (credentialCache != null) webClient.Credentials = credentialCache;
                // webClient.UseDefaultCredentials = true;

                webClient.Headers[HttpRequestHeader.Authorization] = basicAuthorization;
            }

            if (!string.IsNullOrWhiteSpace(ImpersonateUser))
            {
                webClient.Headers.Add("X-Redmine-Switch-User", ImpersonateUser);
            }

            return(webClient);
        }
Пример #4
0
        /// <summary>
        /// Creates the Redmine web client.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        /// <code></code>
        protected WebClient CreateWebClient(NameValueCollection parameters)
        {
            var webClient = new RedmineWebClient();

            webClient.Headers.Add(HttpRequestHeader.ContentType, mimeFormat == MimeFormat.json ? "application/json" : "application/xml");
            webClient.Encoding = Encoding.UTF8;

            if (parameters != null)
            {
                webClient.QueryString = parameters;
            }

            if (!string.IsNullOrEmpty(apiKey))
            {
                webClient.QueryString["key"] = apiKey;
            }
            else
            {
                if (credentialCache != null)
                {
                    webClient.Credentials = credentialCache;
                }
                webClient.UseDefaultCredentials                = true;
                webClient.Headers["Authorization"]             = basicAuthorization;
                webClient.Headers[HttpRequestHeader.UserAgent] = ": Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 4.0.20506)";
                //.Add(HttpRequestHeader.Authorization, basicAuthorization);
            }

            if (!string.IsNullOrWhiteSpace(ImpersonateUser))
            {
                webClient.Headers.Add("X-Redmine-Switch-User", ImpersonateUser);
            }

            return(webClient);
        }
Пример #5
0
        /// <summary>
        /// Creates the Redmine web client.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        /// <code></code>
        protected WebClient CreateWebClient(NameValueCollection parameters)
        {
            var webClient = new RedmineWebClient();

            if (parameters != null)
            {
                webClient.QueryString = parameters;
            }

            if (!string.IsNullOrEmpty(apiKey))
            {
                webClient.QueryString["key"] = apiKey;
            }
            else
            {
                if (cache != null)
                {
                    webClient.Credentials = cache;
                }
            }

            // #if RUNNING_ON_35_OR_ABOVE
            webClient.Headers.Add("Content-Type", mimeFormat == MimeFormat.json ? "application/json; charset=utf-8" : "application/xml; charset=utf-8");
            //  #elseif
            //      webClient.Headers.Add("Content-Type", "application/xml; charset=utf-8");
            //  #endif

            webClient.Encoding = Encoding.UTF8;
            return(webClient);
        }
Пример #6
0
        /// <summary>
        ///     Creates the Redmine web client.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="uploadFile">if set to <c>true</c> [upload file].</param>
        /// <returns></returns>
        /// <code></code>
        public virtual RedmineWebClient CreateWebClient(NameValueCollection parameters, bool uploadFile = false)
        {
            var webClient = new RedmineWebClient {
                Proxy = Proxy
            };

            if (!uploadFile)
            {
                webClient.Headers.Add(HttpRequestHeader.ContentType, MimeFormat == MimeFormat.Xml
                    ? "application/xml"
                    : "application/json");
                webClient.Encoding = Encoding.UTF8;
            }
            else
            {
                webClient.Headers.Add(HttpRequestHeader.ContentType, "application/octet-stream");
            }

            if (parameters != null)
            {
                webClient.QueryString = parameters;
            }

            if (!string.IsNullOrEmpty(ApiKey))
            {
                webClient.QueryString[RedmineKeys.KEY] = ApiKey;
            }
            else
            {
                if (cache != null)
                {
                    webClient.PreAuthenticate = true;
                    webClient.Credentials     = cache;
                    webClient.Headers[HttpRequestHeader.Authorization] = basicAuthorization;
                }
                else
                {
                    webClient.UseDefaultCredentials = true;
                    webClient.Credentials           = CredentialCache.DefaultCredentials;
                }
            }

            if (!string.IsNullOrEmpty(ImpersonateUser))
            {
                webClient.Headers.Add("X-Redmine-Switch-User", ImpersonateUser);
            }

            return(webClient);
        }