为什么Jsoup设置***IP后连接失败

不使用proxy时运行十分稳定,一旦在Connection对象中设置proxy后就报错:connect time out。请求各位大神指导一二

主方法:

public class ProxyIpUtilTest {

    public static void main(String[] args) {

        int code = ProxyIpUtil.checkProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("180.118.134.123", 9000)), "http://www.baidu.com");
        System.out.println(code);

    }

}

ProxyIpUtil.checkProxy():

 public static int checkProxy(Proxy proxy, String validSite){
        try {
            URL url = new URL(validSite!=null?validSite:XxlCrawlerConf.SITE_BAIDU);

            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(proxy);
            httpURLConnection.setRequestProperty("User-Agent", XxlCrawlerConf.USER_AGENT_CHROME);
            httpURLConnection.setConnectTimeout(XxlCrawlerConf.TIMEOUT_MILLIS_DEFAULT);
            httpURLConnection.setReadTimeout(XxlCrawlerConf.TIMEOUT_MILLIS_DEFAULT);

            httpURLConnection.connect();
            int statusCode = httpURLConnection.getResponseCode();

            /*InputStream inputStream = httpURLConnection.getInputStream();
            String content = IOUtil.toString(inputStream, null);
            if(content.indexOf("百度") == -1){
                logger.info(content);
                return -1;
            }*/

            return statusCode;
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            return -2;
        }
    }

报错:

java.net.SocketTimeoutException: connect timed out
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.Socket.connect(Socket.java:589)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
    at sun.net.www.http.HttpClient$1.run(HttpClient.java:515)
    at sun.net.www.http.HttpClient$1.run(HttpClient.java:513)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.http.HttpClient.privilegedOpenServer(HttpClient.java:512)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:553)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
    at sun.net.www.http.HttpClient.New(HttpClient.java:339)
    at sun.net.www.http.HttpClient.New(HttpClient.java:357)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1199)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984)
    at com.xuxueli.crawler.util.ProxyIpUtil.checkProxy(ProxyIpUtil.java:36)
    at com.xuxueli.crawler.test.util.ProxyIpUtilTest.main(ProxyIpUtilTest.java:30)
-2
#Java#
全部评论
系统会对HTTP请求进行拦截吗?还是跑不通😖
点赞 回复 分享
发布于 2019-07-29 14:12

相关推荐

死在JAVA的王小美:哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈,我也是,让我免了一轮,但是硬气拒绝了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务