import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
/**
* Abstract Data Requester from the portal api.snooker.org.
public abstract class AbstractRequester implements Requester {
protected static final String API_SNOOKER_URL = "http://api.snooker.org/";
+ protected static final Charset API_SNOOKER_CHARSET = StandardCharsets.UTF_8;
+
+ private static final String API_SNOOKER_HEADER_NAME = "X-Requested-By";
+ private static final String API_SNOOKER_HEADER_VALUE = "Hedgecode";
protected abstract String getRequestUrl(int id) throws RequestException;
try {
URL url = new URL(requestUrl);
URLConnection urlConnection = url.openConnection();
+ urlConnection.setRequestProperty(
+ API_SNOOKER_HEADER_NAME, API_SNOOKER_HEADER_VALUE
+ );
BufferedReader br = new BufferedReader(
new InputStreamReader(
- urlConnection.getInputStream()
+ urlConnection.getInputStream(), API_SNOOKER_CHARSET
)
);
String inputLine;