Inheritance: HttpIncomingRequestResponse, IDisposable
コード例 #1
0
ファイル: HttpClient.cs プロジェクト: sp00x/internetpack
        public HttpClientResponse Dispatch(HttpClientRequest request)
        {
            HttpClientResponse lResponse = this.TryDispatch(request);

            if ((Int32)lResponse.HttpCode >= 400)
            {
                if (lResponse.HasContentLength)
                {
                    throw new HttpException(lResponse.ContentString, lResponse);
                }

                throw new HttpException(lResponse.Header.ToString(), lResponse);
            }

            return(lResponse);
        }
コード例 #2
0
 public HttpException(String message, HttpClientResponse response, Exception innerException)
     : base(message, innerException)
 {
     this.fResponse = response;
 }
コード例 #3
0
 public HttpException(String message, HttpClientResponse response)
     : base(message)
 {
     this.fResponse = response;
 }
コード例 #4
0
 public HttpException(HttpClientResponse response)
     : base()
 {
     this.fResponse = response;
 }
コード例 #5
0
        public HttpClientResponse TryDispatch(HttpClientRequest request)
        {
            HttpClient.SetAuthorizationHeader(request.Header, "Authorization", this.UserName, this.Password);

            String  lHostname      = request.Url.Hostname;
            Int32   lPort          = request.Url.Port;
            Boolean lSslConnection = String.Equals(request.Url.Protocol, "https", StringComparison.OrdinalIgnoreCase);

            // Settings for connection thru Http Proxy
            // Note that Request should think that it uses direct connection when SSL is enabled because
            // proxy server tunnels SSL data AS IS, without adjusting its HTTP headers
            request.UseProxy = this.ProxySettings.UseProxy && !lSslConnection;
            if (this.ProxySettings.UseProxy)
            {
                lHostname = this.ProxySettings.ProxyHost;
                lPort     = this.ProxySettings.ProxyPort;

                HttpClient.SetAuthorizationHeader(request.Header, "Proxy-Authorization", this.ProxySettings.UserName, this.ProxySettings.Password);
            }

            Connection lConnection = this.GetHttpConnection(lSslConnection, request.Url.Hostname, request.Url.Port, lHostname, lPort);

            try
            {
                request.WriteHeaderToConnection(lConnection);
            }
            catch (ConnectionClosedException)
            {
                lConnection = this.GetNewHttpConnection(lHostname, lPort);
                request.WriteHeaderToConnection(lConnection);
            }
            catch (System.Net.Sockets.SocketException)
            {
                lConnection = this.GetNewHttpConnection(lHostname, lPort);
                request.WriteHeaderToConnection(lConnection);
            }

            request.WriteBodyToConnection(lConnection);

            lConnection.Timeout        = Timeout;
            lConnection.TimeoutEnabled = TimeoutEnabled;

            HttpClientResponse lResponse;

            do
            {
                HttpHeaders lHeaders = HttpHeaders.Create(lConnection);
                if (lHeaders == null)
                {
                    throw new ConnectionClosedException();
                }
                lResponse = new HttpClientResponse(lConnection, lHeaders);
            }while (lResponse.Header.ResponseCode == "100"); // 100 CONTINUE means useless response.

            if (!lResponse.KeepAlive)
            {
                this.fConnectionUrl = null;
                this.fConnection    = null;
            }

            if (lResponse.Code == 407)
            {
                throw new HttpException("Proxy authorization failed", lResponse);
            }

            return(lResponse);
        }
コード例 #6
0
 public Byte[] GetBytes(String url)
 {
     using (HttpClientResponse response = GetResponse(url))
         return(response.ContentBytes);
 }
コード例 #7
0
ファイル: HttpClient.cs プロジェクト: remobjects/internetpack
		public HttpException(String message, HttpClientResponse response, Exception innerException)
			: base(message, innerException)
		{
			this.fResponse = response;
		}
コード例 #8
0
ファイル: HttpClient.cs プロジェクト: remobjects/internetpack
		public HttpException(String message, HttpClientResponse response)
			: base(message)
		{
			this.fResponse = response;
		}
コード例 #9
0
ファイル: HttpClient.cs プロジェクト: remobjects/internetpack
		public HttpException(HttpClientResponse response)
		{
			this.fResponse = response;
		}
コード例 #10
0
ファイル: HttpClient.cs プロジェクト: remobjects/internetpack
		public HttpClientResponse TryDispatch(HttpClientRequest request)
		{
			HttpClient.SetAuthorizationHeader(request.Header, "Authorization", this.UserName, this.Password);

			String lHostname = request.Url.Hostname;
			Int32 lPort = request.Url.Port;
			Boolean lSslConnection = String.Equals(request.Url.Protocol, "https", StringComparison.OrdinalIgnoreCase);

			// Settings for connection thru Http Proxy
			// Note that Request should think that it uses direct connection when SSL is enabled because
			// proxy server tunnels SSL data AS IS, without adjusting its HTTP headers
			request.UseProxy = this.ProxySettings.UseProxy && !lSslConnection;
			if (this.ProxySettings.UseProxy)
			{
				lHostname = this.ProxySettings.ProxyHost;
				lPort = this.ProxySettings.ProxyPort;

				HttpClient.SetAuthorizationHeader(request.Header, "Proxy-Authorization", this.ProxySettings.UserName, this.ProxySettings.Password);
			}

			Connection lConnection = this.GetHttpConnection(lSslConnection, request.Url.Hostname, request.Url.Port, lHostname, lPort);

			try
			{
				request.WriteHeaderToConnection(lConnection);
			}
			catch (ObjectDisposedException)
			{
				lConnection = this.GetNewHttpConnection(lHostname, lPort);
				request.WriteHeaderToConnection(lConnection);
			}
			catch (ConnectionClosedException)
			{
				lConnection = this.GetNewHttpConnection(lHostname, lPort);
				request.WriteHeaderToConnection(lConnection);
			}
			catch (System.Net.Sockets.SocketException)
			{
				lConnection = this.GetNewHttpConnection(lHostname, lPort);
				request.WriteHeaderToConnection(lConnection);
			}

			request.WriteBodyToConnection(lConnection);


			HttpClientResponse lResponse;
			do
			{
				HttpHeaders lHeaders = HttpHeaders.Create(lConnection);
				if (lHeaders == null)
					throw new ConnectionClosedException();
				lResponse = new HttpClientResponse(lConnection, lHeaders);
			}
			while (lResponse.Header.HttpCode == HttpStatusCode.Continue); // 100 CONTINUE means useless response.

			if (!lResponse.KeepAlive)
			{
				this.fConnectionUrl = null;
				this.fConnection = null;
			}

			if (lResponse.HttpCode == HttpStatusCode.ProxyAuthenticationRequired)
				throw new HttpException("Proxy authorization failed", lResponse);

			return lResponse;
		}
コード例 #11
0
ファイル: MainForm.cs プロジェクト: remobjects/internetpack
		private void ShowResponse(HttpClientResponse aResponse)
		{
			_LastResultString = aResponse.ContentString;
			_LastResultBytes = aResponse.ContentBytes;
			try
			{
				_LastLength = aResponse.ContentLength;
			}
			catch
			{
				_LastLength = _LastResultBytes.Length;
			}

			AddResponseHeader(aResponse.Header.FirstHeader, "");
			foreach (HttpHeader aHeader in aResponse.Header)
			{
				AddResponseHeader(aHeader.Name, aHeader.Value);
				if (aHeader.Name == "Set-Cookie")
				{
					if (MessageBox.Show("Keep Cookie for future requests?", "Internet Pack", MessageBoxButtons.YesNo) == DialogResult.Yes)
					{
						DataRow aRow = tblHeaders.NewRow();
						aRow["Name"] = "Cookie";
						aRow["Value"] = aHeader.Value;
						tblHeaders.Rows.Add(aRow);
					}
				}
			}

			SetResultText();
		}
コード例 #12
0
ファイル: HttpClient.cs プロジェクト: pavadik/internetpack
        public HttpClientResponse TryDispatch(HttpClientRequest request)
        {
            HttpClient.SetAuthorizationHeader(request.Header, "Authorization", this.UserName, this.Password);

            String  lHostname      = request.URL.Host;
            Int32   lPort          = request.URL.Port;
            Boolean lSslConnection = request.URL.Scheme?.ToLower() == "https";

            // Settings for connection thru Http Proxy
            // Note that Request should think that it uses direct connection when SSL is enabled because
            // proxy server tunnels SSL data AS IS, without adjusting its HTTP headers
            request.UseProxy = this.ProxySettings.UseProxy && !lSslConnection;
            if (this.ProxySettings.UseProxy)
            {
                lHostname = this.ProxySettings.ProxyHost;
                lPort     = this.ProxySettings.ProxyPort;

                HttpClient.SetAuthorizationHeader(request.Header, "Proxy-Authorization", this.ProxySettings.UserName, this.ProxySettings.Password);
            }

            Connection lConnection = this.GetHttpConnection(lSslConnection, request.URL.Host, request.URL.Port, lHostname, lPort);

            try
            {
                request.WriteHeaderToConnection(lConnection);
            }
            catch (ObjectDisposedException)
            {
                lConnection = this.GetNewHttpConnection(lHostname, lPort);
                request.WriteHeaderToConnection(lConnection);
            }
            catch (ConnectionClosedException)
            {
                lConnection = this.GetNewHttpConnection(lHostname, lPort);
                request.WriteHeaderToConnection(lConnection);
            }
            catch (SocketException)
            {
                lConnection = this.GetNewHttpConnection(lHostname, lPort);
                request.WriteHeaderToConnection(lConnection);
            }

            request.WriteBodyToConnection(lConnection);

            HttpClientResponse lResponse;

            do
            {
                HttpHeaders lHeaders = HttpHeaders.Create(lConnection);
                if (lHeaders == null)
                {
                    throw new ConnectionClosedException();
                }
                lResponse = new HttpClientResponse(lConnection, lHeaders);
            }while (lResponse.Header.HttpCode == HttpStatusCode.Continue);            // 100 CONTINUE means useless response.

            if (!lResponse.KeepAlive)
            {
                this.fConnectionUrl = null;
                this.fConnection    = null;
            }

            if (lResponse.HttpCode == HttpStatusCode.ProxyAuthenticationRequired)
            {
                throw new HttpException("Proxy authorization failed", lResponse);
            }

            return(lResponse);
        }