gpt4 book ai didi

Java URL openStream 抛出异常

转载 作者:行者123 更新时间:2023-12-01 18:11:10 24 4
gpt4 key购买 nike

我有以下代码,但是当我运行它时出现异常

"SocketTimeoutException" at openStream.

代码:

String urlStr = "https://www.nse-india.com/live_market/dynaContent/live_watch/get_quote/getHistoricalData.jsp?symbol=SCHNEIDER&series=EQ&fromDate=01-01-2020&toDate=29-02-2020&datePeriod=&hiddDwnld=true";

URL urlConn = new URL(urlStr);
InputStream in = urlConn.openStream();

当我从浏览器执行相同的 URL 时,它工作正常。

最佳答案

服务器查找两个请求 header ,以下代码有效

        String urlStr = "https://www.nse-india.com/live_market/dynaContent/live_watch/get_quote/getHistoricalData.jsp?symbol=SCHNEIDER&series=EQ&fromDate=01-01-2020&toDate=29-02-2020&datePeriod=&hiddDwnld=true";

URL url = new URL(urlStr);
URLConnection conn = url.openConnection();
conn.setRequestProperty("accept-language", "en-US,en;q=0.9");
conn.setRequestProperty("user-agent", "MyJavaApp");
InputStream in = conn.getInputStream();

关于Java URL openStream 抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60466607/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com