예제 #1
0
        private HTTP_RESPONSE getResponseDetails(HttpWebResponse webResponse)
        {
            HTTP_RESPONSE output = new HTTP_RESPONSE();

            //We should probably pull the Http status code and message body out of the webresposne in here
            //and put it in the HTTP_RESPONSE object.

            return(output);
        }
예제 #2
0
        private HTTP_RESPONSE request(String requestType, String endpoint, String body = null)
        {
            HttpWebRequest request       = WebRequest.CreateHttp(baseUrl + endpoint);
            HTTP_RESPONSE  response      = new HTTP_RESPONSE();
            Stopwatch      responseTimer = new Stopwatch();

            byte[] data = null;
            request.Method      = requestType;
            request.ContentType = "application/json";
            request.KeepAlive   = false;

            foreach (KeyValuePair <String, String> kvp in headers)
            {
                request.Headers.Add(kvp.Key, kvp.Value);
            }

            if (!String.IsNullOrEmpty(body))
            {
                //We should probably add our body to the request's content here
            }

            responseTimer.Start();
            try
            {
                using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
                    response = getResponseDetails(webResponse);

                response.Time = responseTimer.Elapsed;
            }
            catch (WebException exception)
            {
                if (exception.Status == WebExceptionStatus.ProtocolError)
                {
                    using (HttpWebResponse errResponse = (HttpWebResponse)exception.Response)
                        response = getResponseDetails(errResponse);
                    response.Time = responseTimer.Elapsed;
                }
                else
                {
                    throw new Exception(exception.Message);
                }
            }
            responseTimer.Stop();

            return(response);
        }