NutzCN Logo
问答 Http工具类调用有错误,这可咋整啊???
发布于 2709天前 作者 daodaovps 2005 次浏览 复制 上一个帖子 下一个帖子
标签:

Http工具类调用有错误,这可咋整啊???
错误如下

org.nutz.http.HttpException: url=https://apkpure.com/newsdog-latest-news-updates/com.newsdog
	at org.nutz.http.sender.GetSender.send(GetSender.java:22)
	at org.nutz.http.Sender.call(Sender.java:223)
	at basetest.Socket_Gp.getappinfo_02(Socket_Gp.java:118)
	at basetest.Socket_Gp.main(Socket_Gp.java:26)
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
	at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:992)
	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
	at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1513)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
	at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
	at org.nutz.http.Sender.getResponseHeader(Sender.java:124)
	at org.nutz.http.sender.GetSender.send(GetSender.java:19)
	... 3 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
	at sun.security.ssl.InputRecord.read(InputRecord.java:505)
	at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
	... 14 more

我是这么调用的

public static String[] getappinfo_02(String pn) {
        String[] out = new String[3];
        String img = "";
        String title = pn;
        String category = "";

        try {

            Http.disableJvmHttpsCheck();
            if (Lang.isWin()) {
                Http.setSocketProxy("127.0.0.1", 1080);
            } else {
                Http.setSocketProxy("127.0.0.1", 35181);
            }

            Header header = Header.create();
            header.set("Host", "apkpure.com");
            header.set("Connection", "keep-alive");
            header.set("Pragma", "no-cache");
            header.set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36");
            header.set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
            header.set("Accept-Encoding", "gzip, deflate, sdch, br");
            header.set("Accept-Language", "en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2,ja;q=0.2,ko;q=0.2,my;q=0.2");
            header.set("Cookie", "__cfduid=d4736fe159d37d73b872441c6560ea9ca1476684023; _csrf=2U2F7y90F_XOp45AoqtJzFYG; _ga=GA1.2.1555710223.1476684006; __atuvc=7%7C42%2C3%7C43; __atuvs=58106afbc4a5eea6002");

            //jdk.tls.client.protocols=TLSv1
            System.setProperty("jdk.tls.client.protocols", "TLSv1");

//            String reqhref = "https://apkpure.com/search?q=" + pn + "";
            String reqhref = "https://apkpure.com/newsdog-latest-news-updates/com.newsdog";
            Request req = Request.create(reqhref, Request.METHOD.GET, "", header);
            Response resp = Sender.create(req).call();
            if (resp.getStatus() == 301) {
                System.out.println();
            }
//            Response resp = Http.get(reqhref);
            if (resp.getStatus() == 301) {
                System.out.println();
            }


            out[0] = img;
            out[1] = title;
            out[2] = category;

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
       
        }
        return out;
    }
3 回复

我试了一下, 问题在于这里. 详细描述在代码注释中

        Http.disableJvmHttpsCheck(); // 这个网站的https证书没有问题的,这句不需要的.
        if (Lang.isWin()) {
            Http.setSocketProxy("127.0.0.1", 1080); // 1080提供的socks5代理服务,而非Socket代理服务
        } else {
            Http.setSocketProxy("127.0.0.1", 35181);
        }

因为1080不是socket proxy, 需要再弄个 socks5转socket proxy的软件才能给java用的

PS: 上述代码注释掉,挂VPN的情况下,正常运行

添加回复
请先登陆
回到顶部