Ejemplo n.º 1
0
        private static HttpResponseMessage GetResponse(string url, HttpMethod method, string parameters)
        {
            var client = new SitefinityClient();

            client.RequestAuthenticate();
            var request = new HttpRequestMessage(method.ToString(), url);

            switch (method)
            {
            case HttpMethod.POST:
                request.Headers.ContentType = "application/x-www-form-urlencoded";
                break;

            case HttpMethod.PUT:
                request.Headers.ContentType = "text/json";
                break;
            }

            if (parameters != null)
            {
                byte[] bytes = System.Text.Encoding.ASCII.GetBytes(parameters);
                request.Headers.ContentLength = bytes.Length;
                request.Content = HttpContent.Create(bytes);
            }

            client.TransportSettings.MaximumAutomaticRedirections = 5;
            var response = client.Send(request);

            return(response);
        }
        /// <summary>
        /// Make Authenticate GET Request
        /// </summary>
        /// <param name="url">The web request url </param>
        /// <returns>The response from the request</returns>
        public HttpResponseMessage MakeAuthenticateGetRequest(string url)
        {
            var client = new SitefinityClient();

            client.RequestAuthenticate();
            return(client.Send(HttpMethod.GET, url));
        }
        /// <summary>
        /// Make Authenticate PUT Request
        /// </summary>
        /// <param name="url">The web request url </param>
        /// <param name="payload">The payload of the request</param>
        public void MakeAuthenticatePutRequest(string url, string payload)
        {
            var client = new SitefinityClient();

            client.RequestAuthenticate();
            var request = new HttpRequestMessage("put", url);

            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(payload);
            request.Headers.ContentType   = "text/json";
            request.Headers.ContentLength = bytes.Length;
            request.Content = HttpContent.Create(bytes);
            client.Send(request);
        }