estoy tratando de recuperar datos de http://api.freebase.com/api/trans/raw/m/0h47Java codificación UTF-8 no establecida URLConnection
Como se puede ver en el texto existen canta así: /ælˈdʒɪəriə/
.
Cuando intento para conseguir la fuente de la página de recibo de texto con canta como ú
etc.
Hasta ahora he intentado con el siguiente código:
urlConnection.setRequestProperty("Accept-Charset", "UTF-8");
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
¿Qué estoy haciendo mal?
Toda mi código:
URL url = null;
URLConnection urlConn = null;
DataInputStream input = null;
try {
url = new URL("http://api.freebase.com/api/trans/raw/m/0h47");
} catch (MalformedURLException e) {e.printStackTrace();}
try {
urlConn = url.openConnection();
} catch (IOException e) { e.printStackTrace(); }
urlConn.setRequestProperty("Accept-Charset", "UTF-8");
urlConn.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
urlConn.setDoInput(true);
urlConn.setUseCaches(false);
StringBuffer strBseznam = new StringBuffer();
if (strBseznam.length() > 0)
strBseznam.deleteCharAt(strBseznam.length() - 1);
try {
input = new DataInputStream(urlConn.getInputStream());
} catch (IOException e) { e.printStackTrace(); }
String str = "";
StringBuffer strB = new StringBuffer();
strB.setLength(0);
try {
while (null != ((str = input.readLine())))
{
strB.append(str);
}
input.close();
} catch (IOException e) { e.printStackTrace(); }
Parece que lo único que funcionará. Gracias. – Ales
Tengo el mismo problema por favor ayuda. m.appendTail (m); esta linea me error –
@ ersyn61: Perdón, corregido; debería haber sido 'm.appendTail (sb);'. –