Este es el codigo
URL original https://v6.exchangerate-api.com/v6/85cb37c283fc71d11ca21787/latest/USD" en lugar de USD quiero ingresar la consulta del Scanner lectura_moneda = new Scanner(System.in);
codigo import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.Scanner;
import com.google.gson.JsonObject; import com.google.gson.JsonParser; import static java.net.http.HttpClient.newHttpClient;
public class ExchangeRateClient { public static void main(String[] args) throws IOException, InterruptedException { //leer datos que el usuario ingresa
Scanner lectura_moneda = new Scanner(System.in);
System.out.println("Ingrese moneda a consultar");
var moneda = lectura_moneda.nextLine();
String valor_moneda = "https://v6.exchangerate-api.com"+moneda+"/v6/85cb37c283fc71d11ca21787/latest/";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request= HttpRequest.newBuilder()
.uri(URI.create("valor_moneda"))
.build();
HttpResponse<String> response = client
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
//Errores Ingrese moneda a consultar: "AFN" Exception in thread "main" java.lang.IllegalArgumentException: URI with undefined scheme at java.net.http/jdk.internal.net.http.common.Utils.newIAE(Utils.java:378) at java.net.http/jdk.internal.net.http.HttpRequestBuilderImpl.checkURI(HttpRequestBuilderImpl.java:79) at java.net.http/jdk.internal.net.http.HttpRequestBuilderImpl.uri(HttpRequestBuilderImpl.java:71) at java.net.http/jdk.internal.net.http.HttpRequestBuilderImpl.uri(HttpRequestBuilderImpl.java:43) at ExchangeRateClient.main(ExchangeRateClient.java:23)