无法下载Java中的特定URL

问题描述 投票:0回答:1

[我正在编写以下程序,以使用Apache Common-IO下载URL,并且出现ReadTimeOut异常,例外

java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at org.apache.commons.io.FileUtils.copyURLToFile(FileUtils.java:1456)
at com.touseef.stock.FileDownload.main(FileDownload.java:23)

程序

String urlStr = "https://www.nseindia.com/";
    File file = new File("C:\\User\\WorkSpace\\Output.txt");
    URL url;
    try {
        url = new URL(urlStr);
        FileUtils.copyURLToFile(url, file);
        System.out.println("Successfully Completed.");
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

其他站点都可以下载。请提出建议。使用commons-io-2.6 jar。

java url download apache-commons
1个回答
0
投票
例如从Firefox内部运行的请求在Java中不起作用(因为TLS协议和密码的连接不同)。我使用Apache Commons HTTP客户端尝试了几种组合。但也失败了(即使Fiddler发出了相同的请求)。

因此在Java中使用此网站非常困难,即使上面的代码目前都可以使用,保护系统可以随时进行调整,以使其不再起作用。

我会假设这样的站点提供了专用于程序使用的API。与他们联系并询问,这是我能给您的唯一建议。

© www.soinside.com 2019 - 2024. All rights reserved.