encoding/decoding of Strings HTTP/IBM850/ISO8859_1
Hi,
I do a HTTP request in java, the web server send me back html
data encoded in IBM850:
<META content="text/html; charset=IBM850" http-equiv="Content-Type">
For my java program, I need to have String encoded in ISO8859_1, so
I try to do a conversion which does not work.
Any one has an idea to help me ?
Here is the code:
// HTTP request
URL server =new URL("http://www....");
HttpURLConnection connection = (HttpURLConnection) server.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream in = connection.getInputStream();
BufferedReader bin =new BufferedReader(new InputStreamReader( in));
// Read data from the server
StringBuffer sb =new StringBuffer();
String line = bin.readLine();
while (line !=null){
sb.append(line);
sb.append("\r\n");
line = bin.readLine();
}
String resultat = sb.toString();
// Conversion
if ((resultat.indexOf("charset=IBM850")!=-1) || (resultat.indexOf("charset=ibm850")!=-1)){
// conversion to iso latin
try{
resultat =new String(resultat.getBytes("ISO8859_1"),"IBM850");
}catch(java.io.UnsupportedEncodingException uee){
System.out.println("Unsupported conversion");
}
}
Note : the page sent back by the HTTP server is really encoded in IBM850
Internet Explorer or Firefox correctly display the corresponding html page

