예제 #1
0
파일: Program.cs 프로젝트: cannero/restlib
 private static void WriteResponse(RestResponse response)
 {
     if (response.CallSuccessful)
     {
         Console.WriteLine("Call was successful:");
         Console.WriteLine(response.StatusCode);
         Console.WriteLine(response.Content);
     }
     else
     {
         Console.WriteLine("Error during call:");
         Console.WriteLine(response.ErrorStatus);
         Console.WriteLine(response.CompleteErrorMessage);
         Console.WriteLine(response.Content);
     }
 }
예제 #2
0
        /// <summary>
        /// todo all exceptions except WebException have to be handled by user
        /// </summary>
        public RestResponse SendRequest(RestRequest request)
        {
            string url = root + request.GetResourceAndQuery();
            HttpWebRequest httpRequest = CreateHttpRequest(request, url);
            SetData(request, httpRequest);

            RestResponse response;
            try
            {
                HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
                response = new RestResponse(httpResponse);
                this.Cookies.Add(httpResponse.Cookies);
            }
            catch (WebException ex)
            {
                response = new RestResponse(ex);
            }
            return response;
        }