<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    afunms

    My Software,My Dream—Forge a more perfect NMS product.

    java http proxy

    package afu.proxy;

    import java.net.*;
    import java.io.*;

    import org.apache.commons.httpclient.*;
    import org.apache.commons.httpclient.methods.*;

    public class HttpProxy extends Thread
    {
        
    public static int threadNumber = 0;
        
    private static MultiThreadedHttpConnectionManager 
                            connectionManager 
    = new MultiThreadedHttpConnectionManager();
        
    private Socket proxyServer;
        
        
    public HttpProxy(Socket ps)
        
    {
            threadNumber 
    ++;
            proxyServer 
    = ps;
        }

        
        
    public void run()
        
    {                
            DataInputStream proxyIn 
    = null;
            
    try
            
    {
                String clientIP 
    = proxyServer.getInetAddress().toString().substring(1);
                System.out.println(
    "client ip is " + clientIP);
                
                
    /**
                 * visit outside websites through proxy server
                 
    */

                proxyIn 
    = new DataInputStream(proxyServer.getInputStream());    
                String head 
    = proxyIn.readLine();//read the first row
                String method = getMethod(head);
                String requestUrl 
    = getUrl(method.length() + 1 ,head);
                proxy(method,requestUrl);
                
                threadNumber 
    --;
            }

            
    catch(Exception e)
            
    {
                
    //e.printStackTrace();
            }

            
    finally
            
    {
                
    try
                
    {
                    
    if(proxyIn!=null)
                       proxyIn.close();
                    proxyIn 
    = null;
                }

                
    catch(Exception e)
                
    {
                }

            }
            
        }

        
        
    private void proxy(final String methodName,final String requestUrl)
        
    {        
            DataOutputStream proxyOut 
    = null;
            InputStream webIn 
    = null;
            HttpMethod method 
    = null;
            
    try
            
    {
                HttpClient client 
    = new HttpClient(connectionManager);
                
    if("POST".equals(methodName))
                   method 
    = new PostMethod(requestUrl);
                
    else
                   method 
    = new GetMethod(requestUrl);            
                client.executeMethod(method);                                               
                
                webIn 
    = new DataInputStream(new BufferedInputStream(method.getResponseBodyAsStream(),10240));
                proxyOut 
    = new DataOutputStream(proxyServer.getOutputStream());
                
    int num = webIn.read();
                
    while(num!=-1)
                
    {
                    proxyOut.write(num);
                    num 
    = webIn.read();
                }

                proxyOut.flush();
                client 
    = null;
            }
    //try
            catch(Exception e)
            
    {
                
    //e.printStackTrace();
            }

            
    finally
            
    {
                
    try
                
    {
                    proxyOut.close();
                    webIn.close();
                    
    if(method!=null)
                       method.releaseConnection();
                    proxyOut 
    = null;
                    webIn 
    = null;
                    proxyServer.close();
                }

                
    catch(Exception e)
                
    {
                }
                    
            }
            
        }


        
    private String getMethod(final String head)
        
    {
            
    if(head.indexOf("POST")!=-1)
               
    return "POST";    
            
    return "GET";
        }
        
        
        
    private String getUrl(final int startPos,final String head)
        
    {
            
    int loc = head.indexOf("HTTP/1.");
            
    return head.substring(startPos,loc - 1);
        }
        
    }

    package afu.proxy;

    import java.net.ServerSocket;
    import java.net.Socket;

    public class StartProxy
    {    
        
    public void doProxy() 
        
    {        
            
    int port = 808;
            System.out.println(
    "在端口" + port +"啟動(dòng)代理服務(wù)");
            
    try
            
    {
                ServerSocket ss 
    = new ServerSocket(port);
                
    while(true)
                
    {
                    
    if(HttpProxy.threadNumber > 8)
                       
    try 
                       
    {
                           Thread.sleep(
    500); 
                       }
     
                       
    catch(Exception ignored ) 
                       
    {}
                    
    else
                    
    {
                        Socket socket 
    = ss.accept();               
                        HttpProxy proxy 
    = new HttpProxy(socket);           
                        proxy.start();
                    }

                }

            }
        
            
    catch(Exception e)
            
    {
                e.printStackTrace();
            }

        }

    }

    網(wǎng)上找了很多開源的java  http代理程序,都不好用,最后還是自己寫了一個(gè)。

    posted on 2008-08-27 15:41 afunms 閱讀(2462) 評(píng)論(1)  編輯  收藏

    Feedback

    # re: java http proxy 2010-03-23 08:31 Ganky

    你真牛!感覺比我以前下載的好  回復(fù)  更多評(píng)論   



    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    My Links

    News

    留言簿(18)

    隨筆檔案

    相冊(cè)

    搜索

    最新評(píng)論

    閱讀排行榜

    主站蜘蛛池模板: 成年女人永久免费观看片| 免费不卡视频一卡二卡| 亚洲人成网站看在线播放| 中文字幕无码免费久久| 亚洲人成在线免费观看| 亚洲福利在线观看| 亚洲永久在线观看| 三年片在线观看免费大全| 亚洲免费人成视频观看| 日韩免费一区二区三区在线| 97亚洲熟妇自偷自拍另类图片| 免费人成视频在线观看网站| 亚洲欧洲久久精品| 一级毛片一级毛片免费毛片| 国产精品色拉拉免费看| 亚洲一卡二卡三卡| 好吊妞788免费视频播放| 亚洲精品伦理熟女国产一区二区| 日本高清色本免费现在观看| 日韩一区二区三区免费播放| 久久亚洲中文字幕精品一区| 精品国产污污免费网站| 亚洲国产综合第一精品小说| 好吊妞998视频免费观看在线| 美女黄频a美女大全免费皮| 亚洲精品视频在线观看你懂的| 中文字幕乱理片免费完整的| 久久久久亚洲av无码专区喷水 | 精品熟女少妇a∨免费久久| 亚洲毛片一级带毛片基地| 男女免费观看在线爽爽爽视频 | 色偷偷女男人的天堂亚洲网| 日韩高清免费在线观看| 一个人看的www视频免费在线观看 一个人看的免费观看日本视频www | 久久久久久av无码免费看大片| 亚洲精品你懂的在线观看| 最近中文字幕大全免费视频 | 一级特黄特色的免费大片视频| 亚洲AV无码欧洲AV无码网站| 免费精品国产自产拍在线观看图片 | 久久这里只精品99re免费|