【发布时间】:2018-09-28 08:19:00
【问题描述】:
在 java 中,我想从 URL(instagram)读取并保存所有 HTML,但得到错误 429(请求过多)。我认为这是因为我试图阅读比请求限制更多的行。
StringBuilder contentBuilder = new StringBuilder();
try {
URL url = new URL("https://www.instagram.com/username");
URLConnection con = url.openConnection();
InputStream is =con.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String str;
while ((str = in.readLine()) != null) {
contentBuilder.append(str);
}
in.close();
} catch (IOException e) {
log.warn("Could not connect", e);
}
String html = contentBuilder.toString();
错误就是这样;
Could not connect
java.io.IOException: Server returned HTTP response code: 429 for URL: https://www.instagram.com/username/
而且它还表明由于这一行而发生错误
InputStream is =con.getInputStream();
有人知道我为什么会收到此错误和/或如何解决它吗?
【问题讨论】:
-
我认为这是因为我尝试阅读的行数超过了请求限制 ⬅您似乎已经自己回答了您的问题……无论如何,以下内容似乎可能相关:stackoverflow.com/questions/33477861/…,stackoverflow.com/questions/33435965/…,stackoverflow.com/questions/49583489/…
-
我认为你已经达到某种服务器端连接上限;P
标签: java instagram http-status-codes rate-limiting http-status-code-429