Just a unrelated comment about style in using httpclient. The method objects can take a full URL as a constructor, which is cleaner than setting up a HostConfiguration object for a one off request. Also, addParameter has recently been deprecated in favour of setRequestBody with an array of NameValuePairs.

The following is equivelent for preparing the post method for execution:
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://www.vtg.at/samplepath";);
NameValuePair[] parameters = new NameValuePair[]{
new NameValuePair("TXT", "Testtext: öäüÖÄÜß")
};
post.setRequestBody(parameters);


Just a suggestion.
Jandalf.


Mathis Thomas (VTG) wrote:

Got the latest nightly source. I think it's not fixed yet. Am I wrong in expecting the following line?
requestBody=TXT=Testtext%3A%20%F6%E4%FC%D6%C4%DC%DF

My sample code:

public class TestPostCharacterEncoding {

public static void main(String[] args) {
System.out.println( (new Boolean(false)).toString() );

HostConfiguration config = new HostConfiguration();
config.setHost( "www.vtg.at", 80, "http" );

HttpClient client = new HttpClient();
client.setHostConfiguration( config );

PostMethod post = new PostMethod();
post.setHttp11( true );
post.setPath( "/samplepath" );
post.addParameter( "TXT", "Testtext: öäüÖÄÜß");

try {
//post.setRequestHeader( "Content-Type", "text/plain;
charset=ISO-8859-1" );
int ret = client.executeMethod( post );
String s = post.getRequestBodyAsString();
System.out.println( "requestBody=" + s );
} catch (Exception ex ) {
ex.printStackTrace();

}


}
}

RESULT:
requestBody=TXT=Testtext%3A%20%C3%B6%C3%A4%C3%BC%C3%96%C3%84%C3%9C%C3%9F
SHOULD BE:
requestBody=TXT=Testtext%3A%20%F6%E4%FC%D6%C4%DC%DF

-----Ursprüngliche Nachricht-----
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Gesendet: Montag, 3. Februar 2003 15:29
An: Commons HttpClient Project
Cc: Mathis Thomas (VTG)
Betreff: Re: POST method - Default content encoding


The encoding bug in entity enclosing methods (such as POST) has been fixed
right after 2.0 alpha2 release. The problem should go away with the most
recent CVS snapshot. Give it a shot

Cheers

Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to