Last active
April 14, 2023 10:18
-
-
Save theracingapi/85b20143df4cd488293e8c42ed9a6257 to your computer and use it in GitHub Desktop.
Get today's advanced racecards, including UK & IRE odds, using Java (Standard Plan)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.http.HttpRequest; | |
import java.net.http.HttpResponse; | |
import java.net.http.HttpClient; | |
import java.net.URI; | |
import java.io.IOException; | |
import java.util.Base64; | |
class GetRacecards { | |
private static final String getBasicAuthenticationHeader(String username, String password) { | |
String valueToEncode = username + ":" + password; | |
return "Basic " + Base64.getEncoder().encodeToString(valueToEncode.getBytes()); | |
} | |
public static void main(String[] args) { | |
HttpRequest request = HttpRequest.newBuilder() | |
.uri(URI.create("https://api.theracingapi.com/v1/racecards/standard")) | |
.header("Authorization", getBasicAuthenticationHeader("<USERNAME>", "<PASSWORD>")) | |
.method("GET", HttpRequest.BodyPublishers.noBody()) | |
.build(); | |
HttpResponse<String> response = null; | |
try { | |
response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
System.out.println(response.body()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment