Example #1
0
        private HttpWebRequest PrepareRequest(string method, string requestUriString, string endpoint)
        {
            string uriString = String.Format("{0}/{1}", endpoint, requestUriString);
            var    uri       = new Uri(uriString);
            // TODO: ##jwp; need to find out why .NET 4.0 under VS2013 refuses to recognize `WebRequest.CreateHttp`.
            // HttpWebRequest request = WebRequest.CreateHttp(uri);
            var request = WebRequest.Create(uri) as HttpWebRequest;

            request.UserAgent = UserAgent;
            const string ApplicationJsonContentType = "application/json"; // http://tools.ietf.org/html/rfc4627

            request.Accept      = ApplicationJsonContentType;
            request.ContentType = ApplicationJsonContentType;
            request.Method      = method;

            WebHeaderCollection headers = request.Headers;

            headers.Add("Authorization", string.Format("AccessKey {0}", AccessKey));

            if (null != ProxyConfigurationInjector)
            {
                request.Proxy = ProxyConfigurationInjector.InjectProxyConfiguration(request.Proxy, uri);
            }
            return(request);
        }
Example #2
0
        /// <summary>
        /// Prepares a request
        /// </summary>
        /// <param name="requestUriString">URL to call</param>
        /// <param name="method">Request Method (get, post, delete, put)</param>
        /// <returns></returns>
        private HttpWebRequest PrepareRequest(string requestUriString, string method)
        {
            string uriString = String.Format("{0}/{1}", Endpoint, requestUriString);
            var    uri       = new Uri(uriString);
            var    request   = WebRequest.Create(uri) as HttpWebRequest;

            request.UserAgent = UserAgent;
            const string ApplicationJsonContentType = "application/json";                  // http://tools.ietf.org/html/rfc4627
            const string WWWUrlContentType          = "application/x-www-form-urlencoded"; // http://tools.ietf.org/html/rfc4627

            request.Accept = ApplicationJsonContentType;
            //request.ContentType = ApplicationJsonContentType;
            request.ContentType = WWWUrlContentType;
            request.Method      = method;

            if (null != ProxyConfigurationInjector)
            {
                request.Proxy = ProxyConfigurationInjector.InjectProxyConfiguration(request.Proxy, uri);
            }
            return(request);
        }