我正在尝试从Meetup检索此流的数据-http://stream.meetup.com/2/open_events

但是我使用以下代码不断收到错误403

URL meetupStream = new URL("http://stream.meetup.com/2/open_events");
BufferedReader in = new BufferedReader(new InputStreamReader(meetupStream.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null){
      System.out.println(inputLine);
}
in.close();


该流不需要任何身份验证,可以在浏览器中正常看到

有什么想法会导致这种错误吗?

最佳答案

一些网络服务器抱怨您的请求看起来太暗淡,可能是因为他们认为该请求是由机器生成的?通常,他们可以通过您发送的标头分辨出来。这应该已经做到了:

    URLConnection connection = new URL("http://stream.meetup.com/2/open_events").
                                 openConnection();
    connection.setRequestProperty("User-Agent", "Lynx");
    connection.connect();
    BufferedReader in = new BufferedReader(new InputStreamReader(
    connection.getInputStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null){
        System.out.println(inputLine);
    }
    in.close();

关于java - 尝试从Public Stream读取时出现错误403,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38742468/

10-10 07:00