I'm writing an app on Java where I use a GET
request with the OkHttp
library to get some information of a webpage. The webpage is using ISO-8859-1
. There is this tag at the top of the page: <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
.
The code for the GET
request is the following:
Request request = new Request.Builder()
.url(webpage)
.get()
.addHeader("upgrade-insecure-requests", "1")
.addHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36")
.addHeader("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
.addHeader("accept-language", "es-ES,es;q=0.9")
.addHeader("cache-control", "no-cache")
.build();
Response response = client.newCall(request).execute();
String html = response.body().string();
If I print the headers
of the GET
request, I get this: Content-Type: text/html; charset=ISO-8859-1
.
The html
string contains the message that I want to use for the app, but there are some characters that are not readable. For example: the euro symbol (€
), it appears like a question mark (?
) when printed on terminal.
I wanted to know if I can get these symbols in utf-8
enconding.