Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 May : Re: url encode to utf-8
| Subject: | Re: url encode to utf-8 |
| Posted by: | "ildg" (il..@163.com) |
| Date: | 25 May 2006 22:25:24 |
"Ian Stuart" <ian.stuart@chello.at> wrote:
>
>"ildg" <ildg@163.com> wrote in message
>news:44765d4a$1@newsgroups.borland.com...
>>
>>
>>
>> I believe that the function does work.
>> But it's not what I want.
>> What I want is, I want to encode a string as "%xx%yy%zz%dd" format, that's
>> what HttpEncode does. But, Http only encode it to
>> old format, I want it to encode as utf-8 format.
>> For example, I have a string named str that contains Chinese words. When I
>> use HttpEncode(str), I get this result: %BA%BA%D7%D6+%D6%D0%CE%C4. But
>> what I want is:
>> %E6%B1%89%E5%AD%97+%E4%B8%AD%E6%96%87.
>> They are quite different, and it's generated by
>> UrlEncoder.Encode(str,"utf-8") in java. So I come here for help to find
>> out if there's any delphi equivalent.
>>
>> Thank you.
>>
>
>AFAIK, HttpEncode treats utf8 just like a normal string and encodes the
>unsafe characters. You cannot use HttpEncode on a multibyte or wide string
>to get a utf8 encoding.
>
>If you in pass a wide string, the string gets converted to ansi, not utf8.
>You say you have a string with Chinese characters - ansi or widestring?
>
>
>MyChineseWideString is a WideString
>MyMultiByteAnsiString is a String
>
>var
> encodedURL: string;
>
>encodedURL := HttpEncode(UTF8Encode(MyChineseWideString));
>
>or
>
>encodedURL := HttpEncode(AnsiToUTF8(MyMultiByteAnsiString));
>
>
>Regards
>Ian
>
>
Thank you very much. It works now~
none