Пример #1
0
        /// <summary>
        /// Consumes the service at the given URL by invoking a HTTP POST.
        /// </summary>
        /// <param name="url">The service endpoint URL.</param>
        /// <param name="json">The JSON string.</param>
        /// <returns>The service method response.</returns>
        public string Post(string url, string json)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.AllowWriteStreamBuffering = true;
            request.KeepAlive   = false;
            request.Credentials = CredentialCache.DefaultCredentials;
            request.ContentType = "application/json";
            //request.ContentType = "application/x-www-form-urlencoded";
            request.Method = "POST";

            //string parameters = string.Format("{0}={1}", Uri.EscapeDataString("value"), Uri.EscapeDataString(json));
            string parameters = json;

            Stream       requestStream = request.GetRequestStream();
            StreamWriter writer        = new StreamWriter(requestStream);

            writer.Write(parameters);
            writer.Close();

            // Execute the request.
            string result = HttpRequestAgent.ExecuteRequest(request);

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Consumes the service at the given URL by invoking a HTTP GET.
        /// </summary>
        /// <param name="url">The service endpoint URL.</param>
        /// <returns>The service method response.</returns>
        public string Getc(string url)
        {
            // Used to build entire response
            StringBuilder builder = new StringBuilder();

            // Used on each read operation
            byte[] buffer = new byte[8192];

            // Prepare the web service we will consume.
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            // Execute the request.
            string result = HttpRequestAgent.ExecuteRequest(request);

            return(result);
        }