tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andre John Mas <aj...@newtradetech.com>
Subject Re: UTF-8 end to end - what am I doing wrong?
Date Thu, 10 Apr 2003 20:23:05 GMT
Further investigation shows that my problem is probably with the
Apache Commons HttpClient. Using an equivalent approach with
Java's URLConnection the data arrives uncorrupted. I will
continue the investigation on the HttpClient mailing list.

The following code, using Java's URLConnection, works at the
client end:

  public String send(URL destinationUrl, int timeout, String message)
     throws Exception
   {
     //try
     URLConnection connection = destinationUrl.openConnection();
     connection.setRequestProperty("Content-type","text/xml; 
charset=UTF-8");
     connection.setRequestProperty("user-agent", "myAgent");

     connection.setDoInput(true);
     connection.setDoOutput(true);

     OutputStream out = connection.getOutputStream();
     OutputStreamWriter outw = new OutputStreamWriter(out,"utf-8");
     outw.write(message);
     outw.flush();

     InputStream in = connection.getInputStream();
     InputStreamReader inr = new InputStreamReader(in,"utf-8");
     BufferedReader br = new BufferedReader(inr);

     StringBuffer strBuf = new StringBuffer();
     String line = null;
     while ( (line = br.readLine()) != null ) {
       strBuf.append(line);
       strBuf.append('\n');
     }
     return strBuf.toString();
   }



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message