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=db8e5eb407f4f4d9e516f9b66c22f84d43b76844;hpb=edb206228987f506c5dc7a20585537b71f7a2e9d;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 db8e5eb..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. @@ -34,6 +34,9 @@ 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; protected abstract String getRequestUrl(RequestParams params) throws RequestException; @@ -57,6 +60,9 @@ 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(), API_SNOOKER_CHARSET