0
I have an application that consumes data from a network server, follows my code:
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", "Basic " + asB64);
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Access-Control-Allow-Origin", "*");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP Error code : "
+ conn.getResponseCode());
}
InputStreamReader in = new InputStreamReader(conn.getInputStream());
BufferedReader br = new BufferedReader(in);
I’ve already created the object with the data and I’m managing it. The problem is that I needed this application to run in real time to be able to save the data once they were consumed in the database.
That is, you want to save the content read on
br
in the database? If yes, in which table? Which database exactly?– Victor Stafusa
Ah, don’t use the
InputStreamReader
which does not receive encoding, otherwise you will have encoding problems. UseInputStreamReader in = new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8);
.– Victor Stafusa
You can create a service on your server, which runs x in x seconds by calling the script that inserts the data into the database.
– Rodrigo Vaz
@Rodrigo Vaz Any idea where I can get an example?
– Emanuele