예제 #1
0
파일: HClient.cs 프로젝트: biorpg/RT.Util
        private HResponse performRequest(HttpWebRequest request)
        {
            Log.Debug(1, "Requested ({0}) URL \"{1}\"".Fmt(request.Method, request.RequestUri.OriginalString));
            for (int i = 0; i < request.Headers.Count; i++)
            {
                Log.Debug(3, "  " + request.Headers.AllKeys[i] + ": " + request.Headers[i]);
            }
            if (request.CookieContainer != null && request.CookieContainer.Count > 0)
            {
                Log.Debug(3, "  Cookie: " + request.CookieContainer.GetCookieHeader(request.RequestUri));
            }

            HResponse       result;
            HttpWebResponse resp;

            try
            {
                resp = (HttpWebResponse)request.GetResponse();
                if (resp == null)
                {
                    throw new WebException("Received a null response.");
                }
                result = new HResponse(resp);
            }
            catch (WebException e)
            {
                if (e.Response == null)
                {
                    throw new WebException("Caught WebException containing no response.", e);
                }
                else
                {
                    result = new HResponse(resp = (HttpWebResponse)e.Response);
                }
            }
            Log.Debug(2, "Response: " + result.StatusCode + " - " + result.DataString.SubstringSafe(0, 50));
            for (int i = 0; i < resp.Headers.Count; i++)
            {
                Log.Debug(3, "  " + resp.Headers.AllKeys[i] + ": " + resp.Headers[i]);
            }
            return(result);
        }
예제 #2
0
        private HResponse performRequest(HttpWebRequest request)
        {
            Log.Debug(1, "Requested ({0}) URL \"{1}\"".Fmt(request.Method, request.RequestUri.OriginalString));
            for (int i = 0; i < request.Headers.Count; i++)
                Log.Debug(3, "  " + request.Headers.AllKeys[i] + ": " + request.Headers[i]);
            if (request.CookieContainer != null && request.CookieContainer.Count > 0)
                Log.Debug(3, "  Cookie: " + request.CookieContainer.GetCookieHeader(request.RequestUri));

            HResponse result;
            HttpWebResponse resp;
            try
            {
                resp = (HttpWebResponse) request.GetResponse();
                if (resp == null)
                    throw new WebException("Received a null response.");
                result = new HResponse(resp);
            }
            catch (WebException e)
            {
                if (e.Response == null)
                    throw new WebException("Caught WebException containing no response.", e);
                else
                    result = new HResponse(resp = (HttpWebResponse) e.Response);
            }
            Log.Debug(2, "Response: " + result.StatusCode + " - " + result.DataString.SubstringSafe(0, 50));
            for (int i = 0; i < resp.Headers.Count; i++)
                Log.Debug(3, "  " + resp.Headers.AllKeys[i] + ": " + resp.Headers[i]);
            return result;
        }