<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 +"啟動代理服務");
            
    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();
            }

        }

    }

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

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

    Feedback

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

    你真牛!感覺比我以前下載的好  回復  更多評論   



    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    My Links

    News

    留言簿(18)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 国产亚洲精品a在线无码| 日韩免费观看视频| 日韩va亚洲va欧洲va国产| 免费人成大片在线观看播放电影 | 亚洲youwu永久无码精品| 国色精品卡一卡2卡3卡4卡免费| 亚洲国产成人精品青青草原| 国产精品色拉拉免费看| 亚洲欧洲国产综合| 欧美在线看片A免费观看| 亚洲国产精华液2020| 国产不卡免费视频| 深夜免费在线视频| 亚洲精品乱码久久久久久蜜桃不卡| 国产无遮挡色视频免费观看性色| 国内精品久久久久久久亚洲| 久久伊人免费视频| 亚洲一二成人精品区| 嫩草在线视频www免费观看 | 青娱乐免费在线视频| 亚洲日韩一区精品射精| 国产精品免费视频网站| 春意影院午夜爽爽爽免费| 亚洲精品~无码抽插| 最近中文字幕完整版免费高清| 亚洲精品国产日韩| 亚洲国产精品13p| 成全动漫视频在线观看免费高清版下载| 久久夜色精品国产嚕嚕亚洲av| 免费看h片的网站| 亚洲国产一区二区三区在线观看| 亚洲国产精品碰碰| 亚洲人成在线免费观看| 国产午夜亚洲精品不卡| 亚洲VA成无码人在线观看天堂 | 亚洲乱理伦片在线观看中字| 亚洲成a人一区二区三区| 日本一卡精品视频免费| 亚洲精品久久无码av片俺去也| 久久精品亚洲福利| 国产精品成人免费一区二区|