Exemple #1
0
        private void ProxyHttp(GetSocket model, byte[] senddata)
        {
            Method      method  = Method.POST;
            RestRequest request = new RestRequest(method);

            request.AddParameter("url", model.Url);
            request.AddParameter("port", model.Port);
            request.AddParameter("senddata", Convert.ToBase64String(senddata));

            Uri        uri    = new Uri(ProxyHttpurl);
            RestClient client = new RestClient();

            client.BaseUrl = uri;
            IRestResponse response = client.Execute(request);

            byte[] data = Convert.FromBase64String(response.Content);

            if (data.Length > 0)
            {
                model.socket.Send(data);
                AcceptFlowNum += data.Length;
                ShowFlowLabel();
            }
            model.socket.Close();
        }
Exemple #2
0
        private void receiveData(object obj)
        {
            try
            {
                id++;
                Socket    socket = (Socket)obj;
                GetSocket model  = new GetSocket(socket, user, id);
                model.GetHeard();

                if (model.Method == "CONNECT")
                {
                    //Socket socketproxy = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                    //socketproxy.Connect("127.0.0.1", 1080);
                    //socketproxy.Send(model.data);

                    //int datalen = socketproxy.Available;
                    //byte[] dataproxy = new byte[datalen];

                    //while (datalen == 0)
                    //{
                    //    datalen = socketproxy.Available;
                    //    Thread.Sleep(10);
                    //}

                    //while (datalen > 0)
                    //{
                    //    dataproxy = new byte[datalen];
                    //    socketproxy.Receive(dataproxy, datalen, SocketFlags.None);
                    //    datalen = socketproxy.Available;
                    //}
                    //model.socket.Send(dataproxy);

                    string creatok = "HTTP/1.1 200 Connection established\r\n\r\n";
                    model.socket.Send(Encoding.ASCII.GetBytes(creatok));

                    listsocket.Add(model);

                    //while (true)
                    //{
                    //    Thread.Sleep(10);
                    //}

                    //datalen = socketproxy.Available;
                    //while (datalen == 0)
                    //{
                    //    datalen = socketproxy.Available;
                    //    Thread.Sleep(10);
                    //}

                    //while (datalen > 0)
                    //{
                    //    dataproxy = new byte[datalen];
                    //    socketproxy.Receive(dataproxy, datalen, SocketFlags.None);
                    //    datalen = socketproxy.Available;
                    //}
                }
                else if (model.Method == "GET" || model.Method == "POST" || model.Method == "HEAD")
                {
                    model.AcceptContent();
                    ProxyHttp(model, model.data);
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }