":" to %3A
"/" to %2F
"+" to %2B

That's not Base64!  Maybe that could be called "Base16"?  Usually it's just
called URL-Encoding, hence the mime-type "application/x-*www-url-encoded".
*Integer.toHexString( int ) is all you need to create these things.  And
Integer.parseInt( String, 16 ) is all you need to parse these things.

Here's an example "URL-Encoder" in Java:

char c = ...  // character to encode
switch ( c ) {
 case ' ':
   buf.append( '+' );
   break;
 case '$':
 case '<':
 case '>':
 case '&':
 case '+':
 case ',':
 case '/':
 case ':':
 case ';':
 case '=':
 case '?':
 case '@':
 case '#':
 case '%':
   buf.append( '%' );
   buf.append( Integer.toHexString( c ) );
   break;
 default:
   buf.append( c );
   break;
}


yours,

Julius



On 12/6/06, Marcelo Chryssovergis <[EMAIL PROTECTED]> wrote:

Hello,

I believe we have similar situations.

Actually I don´t need (and I can´t) encode the whole string, only chars
considered invalid to base64.
What I am doing is the same as you: I´m replacing some chars explicitly to
the corresponding one in base64.

Example:
":" to %3A
"/" to %2F
"+" to %2B

The problem here, is that I missing some char and getting an error from
server: "Invalid character in a Base-64 string."

Well, back to my research :)

Thanks,
Marcelo.


----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "HttpClient User Discussion" <[email protected]>
Sent: Wednesday, December 06, 2006 11:44 AM
Subject: Re: Re: PostMethod - parameter in BASE64String


> hello,
>
> I am using NameValuePairs to transfer some strings
> to a server with the following content type:
>
> application/x-www-form-urlencoded
>
> My content change from  "!"  to  "%12"
>
> Can I also use encoder/decoder for my strings or
> is  there a better way to transfer data correctly?
>
> Which kind of charset should I use?
>
> bastian
>
>
>
>>  import org.apache.commons.codec.binary.Base64;
>>
>> byte[] bytes = "I love my byte array".getBytes();
>> byte[] base64Bytes = Base64.encodeBase64( bytes );
>>
>> System.out.println( new String( base64Bytes ) );
>> Outputs:
>>
>> SSBsb3ZlIG15IGJ5dGUgYXJyYXk=
>>
>> Good luck!  Like Roland said, "commons-codec.jar" is already on your
>> classpath.  The Base64 class is available for you to use.
>>
>> yours,
>>
>> Julius
>>
>>
>> On 12/6/06, Roland Weber <[EMAIL PROTECTED]> wrote:
>> >
>> > Hello Marcelo,
>> >
>> > it is not the same encoding used in URLs.
>> > HttpClient does not have a Base64 encoder,
>> > but it uses commons-codec for this purpose.
>> >
>> > hope that helps,
>> >   Roland
>> >
>> > "Marcelo Chryssovergis" <[EMAIL PROTECTED]> wrote on 06.12.2006
>> > 15:16:46:
>> >
>> > > Hello,
>> > >
>> > > I´m trying to login to a asp.net site.
>> > >
>> > > I´m using the postmethod to send the data, but one of the fields of
>> > > the framework .Net (VIEWSTATE) has to be converted in a
>> > > Base64String. I believe that´s the same encoding used in URLs.
>> > >
>> > > Is there any function in httpclient to encode the string to base64?
>> > >
>> > > Thanks,
>> > > Marcelo
>> >
>> >
>> >
>>
>>
>> --
>> yours,
>>
>> Julius Davies
>> 416-652-0183
>> http://juliusdavies.ca/
>
> --
> Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
> Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
>
> ---------------------------------------------------------------------
> 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]




--
yours,

Julius Davies
416-652-0183
http://juliusdavies.ca/

Reply via email to