I am trying to run an Api request from yahoo Finance but something is not right. I am getting a java: unreported exception java.io.IOExceotion error.
This is the current requerest:
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/v2/get-chart?interval=5m&symbol=AMRN&range=1d®ion=US"))
.header("x-rapidapi-key", "72d781e00bmsh5b6e67e1b515e76p1c53a1jsn0c19b3ed2e1a")
.header("x-rapidapi-host", "apidojo-yahoo-finance-v1.p.rapidapi.com")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
This is the error I am getting:
C:\Users\L\Documents\CS\PROJECTSPRINGBOOT\WebHel\src\com\company\Main.java:18:72
java: unreported exception java.io.IOException; must be caught or declared to be thrown
How can I solve this problem? I am using rapidAPI.