X-Git-Url: https://git.hedgecode.org/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fhedgecode%2Fsnooker%2Frequest%2FAbstractRequester.java;h=ca4466caefade030c70215677f207dc5f0768e97;hb=cd2f8a9c9fea202a4edb2a475e1455ef879cd6a2;hp=a127bb53a6c462bf50f5803e4ec19a98d64734fc;hpb=8a35619be41b2db6d339f8f0a7f3ba0fc1ca1ed4;p=snooker-score-api.git diff --git a/src/main/java/org/hedgecode/snooker/request/AbstractRequester.java b/src/main/java/org/hedgecode/snooker/request/AbstractRequester.java index a127bb5..ca4466c 100644 --- a/src/main/java/org/hedgecode/snooker/request/AbstractRequester.java +++ b/src/main/java/org/hedgecode/snooker/request/AbstractRequester.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017. Developed by Hedgecode. + * Copyright (c) 2017-2020. Developed by Hedgecode. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,8 @@ import java.io.IOException; 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. @@ -30,6 +32,10 @@ import java.net.URLConnection; 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; @@ -54,9 +60,12 @@ public abstract class AbstractRequester implements Requester { 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;