为什么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

相关推荐

11-30 11:07
河南大学 Java
宇宙厂 测开 n*15
丘丘给个offer:有后选后
点赞 评论 收藏
分享
评论
点赞
收藏
分享
正在热议
# 25届秋招总结 #
443331次浏览 4520人参与
# 春招别灰心,我们一人来一句鼓励 #
42187次浏览 537人参与
# 阿里云管培生offer #
120447次浏览 2220人参与
# 地方国企笔面经互助 #
7973次浏览 18人参与
# 同bg的你秋招战况如何? #
77166次浏览 569人参与
# 实习必须要去大厂吗? #
55811次浏览 961人参与
# 北方华创开奖 #
107472次浏览 600人参与
# 虾皮求职进展汇总 #
116310次浏览 887人参与
# 如果你有一天可以担任公司的CEO,你会做哪三件事? #
11683次浏览 289人参与
# 实习,投递多份简历没人回复怎么办 #
2454962次浏览 34861人参与
# 提前批简历挂麻了怎么办 #
149927次浏览 1978人参与
# 在找工作求抱抱 #
906124次浏览 9423人参与
# 如果公司给你放一天假,你会怎么度过? #
4762次浏览 55人参与
# 你投递的公司有几家约面了? #
33209次浏览 188人参与
# 投递实习岗位前的准备 #
1196037次浏览 18550人参与
# 机械人春招想让哪家公司来捞你? #
157648次浏览 2267人参与
# 双非本科求职如何逆袭 #
662384次浏览 7397人参与
# 发工资后,你做的第一件事是什么 #
12806次浏览 62人参与
# 工作中,努力重要还是选择重要? #
35906次浏览 384人参与
# 简历中的项目经历要怎么写? #
86937次浏览 1516人参与
# 参加完秋招的机械人,还参加春招吗? #
20153次浏览 240人参与
# 我的上岸简历长这样 #
452074次浏览 8089人参与
牛客网
牛客企业服务