Index: src/java/org/apache/commons/httpclient/methods/StringRequestEntity.java =================================================================== --- src/java/org/apache/commons/httpclient/methods/StringRequestEntity.java (revision 354387) +++ src/java/org/apache/commons/httpclient/methods/StringRequestEntity.java (working copy) @@ -53,20 +53,27 @@ /** The content type (i.e. text/html; charset=EUC-JP). */ private String contentType; + /** Default content encoding chatset */ + private static final String DEFAULT_CHARSET = "ISO-8859-1"; /** - * Creates a new entity with the given content - * + * Creates a new entity with the given content. The request entity will use + * the default HTTP encoding ISO-8859-1 to convert characters to bytes + * * @param content The content to set. */ - public StringRequestEntity(String content) { + public StringRequestEntity(final String content) { super(); if (content == null) { throw new IllegalArgumentException("The content cannot be null"); } this.contentType = null; - this.charset = null; - this.content = content.getBytes(); + this.charset = DEFAULT_CHARSET; + try { + this.content = content.getBytes(DEFAULT_CHARSET); + } catch (UnsupportedEncodingException ex) { + this.content = content.getBytes(); + } } /** @@ -100,12 +107,15 @@ break; } } - if (charset == null && charsetPair != null) { + if ((charset == null) && (charsetPair != null)) { // use the charset from the content type this.charset = charsetPair.getValue(); - } else if (charset != null && charsetPair == null) { + } else if ((charset != null) && (charsetPair == null)) { // append the charset to the content type this.contentType = contentType + "; charset=" + charset; + } else if ((charset != null) && (charsetPair != null)) { + if (!charset.equals(charsetPair.getValue())) + throw new IllegalArgumentException("charset and contentType specify a different character set"); } } if (this.charset != null) {