Olá, esse é meu código:
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class PrincipalComBusca {
public static void main (String[] args) throws IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(" http://www.omdbapi.com/?i=matrix&apikey=12286074"))
.build();
HttpResponse<String> response = client
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
e está dando esses erros:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in scheme name at index 0: http://www.omdbapi.com/?i=matrix&apikey=12286074
at java.base/java.net.URI.create(URI.java:906)
at br.com.alura.screenmatch.principal.PrincipalComBusca.main(PrincipalComBusca.java:13)
Caused by: java.net.URISyntaxException: Illegal character in scheme name at index 0: http://www.omdbapi.com/?i=matrix&apikey=12286074
at java.base/java.net.URI$Parser.fail(URI.java:2974)
at java.base/java.net.URI$Parser.checkChars(URI.java:3145)
at java.base/java.net.URI$Parser.checkChar(URI.java:3155)
at java.base/java.net.URI$Parser.parse(URI.java:3170)
at java.base/java.net.URI.<init>(URI.java:623)
at java.base/java.net.URI.create(URI.java:904)
... 1 more
Process finished with exit code 1