Exemple #1
0
        public HttpResult httpSendData(String host, int port, int connectTimeout, String encode, byte[] data)
        {
            TcpClient socket = null;

            try
            {
                socket = new TcpClient(host, port);
                socket.ReceiveTimeout = connectTimeout;
                socket.SendTimeout    = connectTimeout;
                socket.Client.IOControl(IOControlCode.KeepAliveValues, inOptionValues, null);
                if (!socket.Connected)
                {
                    return(null);
                }
                socket.GetStream().Write(data, 0, data.Length);
                socket.GetStream().Flush();
                HttpResult result = HttpResultParse.loadSockerStream(socket.GetStream(), encode, result_type);
                return(result);
            }
            catch
            {
                return(null);
            }
            finally
            {
                try
                {
                    socket.Close();
                }
                catch { }
            }
        }
Exemple #2
0
        public static HttpResult httpsSendData(String host, int port, int connectTimeout, String encode, byte[] data, bool Type)
        {
            TcpClient socket = null;

            try
            {
                socket = new TcpClient(host, port);
                socket.ReceiveTimeout = connectTimeout;
                socket.SendTimeout    = connectTimeout;
                if (!socket.Connected)
                {
                    deathHost.Add(host);
                    return(null);
                }
                SslStream sslStream = new SslStream(socket.GetStream(), true
                                                    , new RemoteCertificateValidationCallback((sender, certificate, chain, sslPolicyErrors)
                                                                                              =>
                {
                    return(sslPolicyErrors == SslPolicyErrors.None);
                }
                                                                                              ), null);
                sslStream.ReadTimeout  = connectTimeout;
                sslStream.WriteTimeout = connectTimeout;
                X509Store store = new X509Store(StoreName.My);
                sslStream.AuthenticateAsClient(host, store.Certificates, System.Security.Authentication.SslProtocols.Tls, false);
                sslStream.Write(data, 0, data.Length);
                sslStream.Flush();
                HttpResult result = HttpResultParse.loadSockerStream(sslStream, encode, host, Type);
                return(result);
            }
            catch (SocketException)
            {
                deathHost.Add(host);
                return(null);
            }
            catch (System.Exception)
            {
                return(null);
            }
            finally
            {
                try
                {
                    if (socket != null && socket.Connected)
                    {
                        socket.Close();
                    }
                }
                catch { }
            }
        }
Exemple #3
0
        public static HttpResult httpSendData(String host, int port, int connectTimeout, String encode, byte[] data, bool Type)
        {
            TcpClient socket = null;

            try
            {
                socket = new TcpClient(host, port);
                socket.ReceiveTimeout = connectTimeout;
                socket.SendTimeout    = connectTimeout;
                if (!socket.Connected)
                {
                    deathHost.Add(host);
                    return(null);
                }
                socket.Client.Send(data, SocketFlags.None);
                socket.GetStream().Flush();
                HttpResult result = HttpResultParse.loadSockerStream(socket.GetStream(), encode, host, Type);
                return(result);
            }
            catch (SocketException)
            {
                deathHost.Add(host);
                return(null);
            }
            catch
            {
                return(null);
            }
            finally
            {
                try
                {
                    if (socket != null && socket.Connected)
                    {
                        socket.Close();
                    }
                }
                catch { }
            }
        }