Re: Problems with japanese characters
Re: Problems with japanese characters
- Subject: Re: Problems with japanese characters
- From: Development <email@hidden>
- Date: Sun, 26 Jul 2009 14:59:55 -0700
On Jul 26, 2009, at 2:45 PM, Greg Guerin wrote:
Development wrote:
I send the data with UTF8 encoding and this is what it sends:
Êó•Êú¨ which makes no sense. this comes from NSLog(@"%s",
[[location objectForKey:@"Country]UTF8String]);
It does make sense if %s is ignorant of character encodings, and
NSLog isn't decoding it as utf8. For example, if it's being decoded
as MacRoman or some other byte-per-character encoding.
NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString
UTF8String ] length: [ myRequestString length ] ];
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ]
initWithURL:url];
[ request setHTTPMethod: @"POST" ];
[ request setHTTPBody: myRequestData ];
[request setValue:@"application/x-www-form-urlencoded"
forHTTPHeaderField:@"content-type"];
This doesn't work because you're sending binary UTF8 as the content-
body, but your content-type header is declaring form-urlencoded.
You need to urlencode the UTF8 bytes, then set that as the body.
Doing the basic arithmetic, the two Unicode code-points 日本 will
encode into six UTF8 bytes (3 bytes for each code-point). Since
each one of those bytes will always be in the range 0x80-0xFF (by
the definition of UTF8), then each byte will be URLEncoded into a 3-
byte sequence "%xx" where each "x" is in the range of chars [0-9a-
f]. So in the end, after all the coding is done, you should have a
total of 3*3 or 9 bytes. Each byte will be either a '%' or a digit
'0'-'9' or a letter 'a'-'f'. If that isn't what's sent as the
content body and what gets received by the server, then something is
wrong.
If that doesn't make sense, then you should probably review the
details of character encodings, especially UTF8 and URL-encoding.
-- GG
Actually thank you this does make a lot of sense and I will begin
corrections.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden