Parsing a JSON url
I am trying to understand why I am unable to load symbols from a webpage and I am confused.
When I try to make one website like jakarta.apache.org; I can track the output well. When I try to use the NBA site, I try to parse; it just spins.
Any idea what I can do?
//http://stats.nba.com/stats/commonplayerinfo?PlayerID=201566
String works= "http://jakarta.apache.org";
String doesntwork= "http://stats.nba.com/stats/commonplayerinfo?PlayerID=201566";
InputStream in = new URL(eitherOne).openStream();
try {
System.out.println( IOUtils.toString( in ) );
}
finally {
IOUtils.closeQuietly(in);
}
I have tried registering the url and when I copy and paste it; it loads fine in the browser. So not sure what else might explain why it works at one address and not another.
+3
source to share
1 answer
Turns off stats.nba.com, restricts some users. To get around this; I changed the user agent to simulate a browser i.e.
conn.setRequestProperty("User-Agent","Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Mobile Safari/537.36");
0
source to share