I’ve been trying to run this Java code to pull the data from the TBA API:
try {
URL url = new URL("https://thebluealliance.com/api/v2/event/2017cama/stats?X-TBA-App-Id=frc5817:eventanalyzer:v02");
HttpURLConnection httpcon = (HttpURLConnection) url.openConnection();
httpcon.addRequestProperty("User-Agent", "Mozilla/5.0");
InputStream is = httpcon.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = null;
// read each line and write to System.out
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch(Exception e) {
e.printStackTrace();
}
And it prints this out in the console:
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.thebluealliance.com/api/v2/event/2017cama/stats?X-TBA-App-Id=frc5817:eventanalyzer:v02">here</A>.
</BODY></HTML>
But when I follow the exact same link in Chrome, it outputs the JSON data fine. I feel like there is some simple thing I’m missing. Can anyone help me out?