Realizei o exercício prático para consumir a api TheMealDb, porém tive um retorno que não consegui corrigir.
Meu código:
import java.io.IOException;
import java.net.*;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Scanner;
public class ConsultaTheMealDB {
public static void main(String[] args) throws IOException, InterruptedException {
Scanner ingrediente = new Scanner(System.in);
System.out.println("Informe um ingrediente: ");
var escolhido = ingrediente.nextLine();
String endereco = "http://www.themealdb.com/api/json/v1/1/search.php?s=" + escolhido;
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(endereco))
.build();
HttpResponse<String> response = client.send(request,HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
Erro ao realizar a chamada:
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>cloudflare</center>
</body>
</html>