为什么我在java中连接第二页的网址,得到的确实第一页的内容
时间: 2024-02-16 16:04:05 浏览: 20
可能是因为你在 Java 中的代码中没有正确设置请求的参数。如果你使用的是 `HttpURLConnection` 类或者其他类似的网络请求库,你需要在请求中设置正确的参数,包括页码和时间戳。具体来说,你需要将页码和时间戳作为请求参数添加到 URL 中,然后发送网络请求。
在你的代码中,你可以使用类似下面的代码来设置请求参数:
```java
int page = 2;
long timestamp = System.currentTimeMillis();
String url = "https://lozhaodaove.lofter.com/?page=" + page + "&t=" + timestamp;
// 创建网络请求
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
// 设置请求方法
connection.setRequestMethod("GET");
// 发送请求
connection.connect();
// 读取响应内容
InputStream inputStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
```
注意,在这个示例代码中,我们使用了当前时间戳来作为请求参数 `t` 的值,这个值应该与服务器返回的时间戳一致,否则可能会导致请求失败或者返回错误的内容。