I am making a request to twitch api with the following code
URL url = new URL("https://api.twitch.tv/kraken/streams/?channel=" + channelID)
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.addRequestProperty("Accept", "application/vnd.twitchtv.v5+json");
connection.addRequestProperty("Client-ID", clientID);
connection.setUseCaches(false);
connection.setDoInput(true);
InputStream inputStream = connection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String line;
StringBuilder response = new StringBuilder();
while ((line = br.readLine()) != null) {
response.append(line);
response.append("\r");
}
br.close();
return response.toString();
This gets the correct response on windows, however when i run it on my Raspberry PI it gets a 400 response. I found a similar question on Stack Overflow i tried to set the proxy settings with this code
System.setProperty("java.net.useSystemProxies", "true");
However this failed to fix this request, any idea what is causing this?
Just incase anyone comes accross this problem in the future, i upgraded to java 11 and implemented it using http client in java 11 i have no idea at all why this fixes the issue but it does.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.