hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicolas Beucler <nicolas.beuc...@teamlog.com>
Subject Re: French accents problem while sending postMethod
Date Tue, 22 Sep 2009 12:54:44 GMT
So i suppose, then that it's the other side that doesen't decode
correctly the XML string?

Regards.

Nicolas
Oleg Kalnichevski a écrit :
> On Tue, Sep 22, 2009 at 11:35:32AM +0200, Nicolas Beucler wrote:
>   
>> Hi All,
>>
>> Seems that i have some problem to send parts containing non ascii
>> characters using multi part post request.
>>
>> What i do is :
>> [CODE]
>> FilePartSource fileSource = new FilePartSource(f);
>>             Part[] parts = { new StringPart("commandxml", commandxml,
>> "UTF-8"),
>>                     new FilePart("uploadFile", fileSource) };
>> //            Part[] parts = { new StringPart("commandxml", commandxml,
>> "ISO-8859-1"),
>> //                    new FilePart("uploadFile", fileSource) };
>>             postMethode.setRequestEntity(new MultipartRequestEntity(parts,
>>                     postMethode.getParams()));
>>             client = new HttpClient();
>>             client.getHostConfiguration().setProxy(
>>                     BatchBol.propMan.getProperty("proxyHost"),
>>                    
>> Integer.valueOf(BatchBol.propMan.getProperty("proxyPort")));
>>            
>> client.getHttpConnectionManager().getParams().setConnectionTimeout(
>>                     5000);
>>             int status = client.executeMethod(postMethode);
>> [/CODE]
>> calling a web service sending multi part post.
>>
>> The first part consist in a xml formated string such as :
>>
>> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
>> <createdocument>
>>     <authentication
>> token="Cnk05awANGBw1epAOnApcPy3RueQCk_evrpBt0UPiLtVEmCKXL-5XSko71coaryt-Lk8O_Yrz9e-BOn7NexdFA"/>
>>     <workspace name="WorkspaceName" id="14058"/>
>>     <category id="38181"/>
>>     <parent id="14836645"/>
>>     <attributes>
>>         <attribute value="Test ADEX" name="TITLE"/>
>>         <attribute value="Mes r?f : 12345" name="REFERENCE"/>
>>         <attribute value="12345" name="REVISION"/>
>>         <attribute value="20/09/2009" name="DUE_DATE"/>
>>     </attributes>
>> </createdocument>
>>
>> and the second part is a file.
>>
>> See attached file to have a look at the code.
>>
>> What's happen is that the "Mes r?f" thing becomes Mes r[0xc3][0xa9]f and
>> unfortunatly doesn't work with the server side.
>>
>>     
>
> This is a perfectly valid UTF-8 representation of this character.
>
> ---
> String s = "�";
> byte[] raw = s.getBytes(Charset.forName("UTF-8"));
> for (int i = 0; i < raw.length; i++) {
>     System.out.print("0x" + Integer.toHexString((raw[i] & 0xFF)) + " ");
> }
> ---
>   
>> 0xc3 0xa9 
>>     
> ---
>
> Oleg
>
>
>
>   
>> It seems that when HttpClient create the parts it re-encodes the content
>> (red and bold in the log trace):
>>
>>     
>>>> "Content-Type: "
>>>>         
>> 2009-09-22 11:32:38,691 DEBUG [httpclient.wire.content] - >> "text/plain"
>> 2009-09-22 11:32:38,691 DEBUG [httpclient.wire.content] - >> "; charset="
>> 2009-09-22 11:32:38,691 DEBUG [httpclient.wire.content] - >> "UTF-8"
>> 2009-09-22 11:32:38,691 DEBUG [httpclient.wire.content] - >> "[\r][\n]"
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >>
>> "Content-Transfer-Encoding: "
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >> "8bit"
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >> "[\r][\n]"
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >> "[\r][\n]"
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >> "<?xml
>> version="1.0" encoding="UTF-8" standalone="yes"?>[\n]"
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >>
>> "<createdocument>[\n]"
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >> "   
>> <authentication
>> token="wHBqUT18Ok0ypUwr8ldqUdzeFw1BuxZUb7gyTaSyzSxFmSJiASEqbTJi5vfQo-lihZ7l8iNWob2rDIqX_XDvkQ"/>[\n]"
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >> "   
>> <workspace name="Veritas SandBox" id="14058"/>[\n]"
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >> "   
>> <category id="38181"/>[\n]"
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >> "   
>> <parent id="14836645"/>[\n]"
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >> "   
>> <attributes>[\n]"
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >> "       
>> <attribute value="Test ADEX" name="TITLE"/>[\n]"
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >> "       
>> <attribute value="*Mes r[0xc3][0xa9]f *: 12345" name="REFERENCE"/>[\n]"
>> 2009-09-22 11:32:38,707 DEBUG [httpclient.wire.content] - >> "       
>> <attribute value="12345" name="REVISION"/>[\n]"
>> 2009-09-22 11:32:38,722 DEBUG [httpclient.wire.content] - >> "       
>> <attribute value="20/09/2009" name="DUE_DATE"/>[\n]"
>> 2009-09-22 11:32:38,722 DEBUG [httpclient.wire.content] - >> "   
>> </attributes>[\n]"
>> 2009-09-22 11:32:38,722 DEBUG [httpclient.wire.content] - >>
>> "</createdocument>[\n]"
>> 2009-09-22 11:32:38,722 DEBUG [httpclient.wire.content] - >> "[\r][\n]"
>> 2009-09-22 11:32:38,722 DEBUG [httpclient.wire.content] - >> "--"
>> 2009-09-22 11:32:38,722 DEBUG [httpclient.wire.content] - >>
>> "qL7OM3nhrkaLANtlVTT5cn1bnsFM9T"
>> 2009-09-22 11:32:38,722 DEBUG [httpclient.wire.content] - >> "[\r][\n]"
>>
>> Any idea of what to do to correctly handle latin chars?
>>
>> Best regards
>>
>> Nicolas.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message