Issues reading from TBA API with Java

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?

These two URLs are different (no “www.” vs having “www.”). Chrome will automatically follow the 301, it seems like Java does not. Have you tried using the “www.” URL?

Thanks! I knew it was something silly like that but I couldn’t figure it out for the life of me. Guess URL autofill has made me lazy :smiley:

You are doing it already, but in case someone finds this in a search later, make sure you use the https URL as well.

This seems like an interesting API to suit your needs