Formicka / exchangerate.host

Exchange rates API is a simple and lightweight free service for current and historical foreign exchange rates & crypto exchange rates.
https://exchangerate.host
357 stars 33 forks source link

Handshake_failure Exception #218

Open rlingeh opened 1 year ago

rlingeh commented 1 year ago

I get a Handshake error exception when I try to connect more than once to get exchange rates. The first connection always works but the second will fail. The first connection can have the endpoint "https://api.exchangerate.host/convert?from=USD&to=EUR", this will succeed and if I try again with the same endpoint or a different one like "https://api.exchangerate.host/convert?from=USD&to=XAF", it fails. If I restart my application, the first connection works again. It looks like I am doing something wrong. I noticed that so long as my app is up I can only connect once. Here is my code:

_String endpoint = URL url = new URL(endpoint); HttpURLConnection request = (HttpURLConnection) url.openConnection(); request.connect(); // fails here by second connection

JsonParser jp = new JsonParser();
JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
JsonObject jsonobj = root.getAsJsonObject();

request.disconnect(); // Still fails with or without this line._