Saturday, December 21, 2013

NSMutableURLRequest post Chinese garbled, how to do, is already utf8

 
NSString * postString = [NSString stringWithFormat: @ "~ WriteMessage #% @ #% @ # 4 # I love you # 3 # 0", [Person sharedInstance] userID, bizID.];

NSData * postData = [postString dataUsingEncoding: NSUTF8StringEncoding allowLossyConversion: YES];

NSLog (@ "post data =% @", postString);

NSMutableURLRequest * request = [[[NSMutableURLRequest alloc] init] autorelease];

[Request setURL: [NSURL URLWithString: [NSString stringWithFormat: @ "% @", KUrl]]];

[Request setHTTPMethod: @ "POST"];

[Request setHTTPBody: postData];

[NSURLConnection connectionWithRequest: request delegate: self];


Reply:
How to see is garbled?
Reply:
Server database to see is garbled,
Reply:
Server is how decoding. Originally, I have encountered, because the server using GBK encoding. What you need to look up the server encoding, database what is coded. Need unity.
Reply:
This encounter, based on your description, I analyzed the reasons may be as follows:
The encoded data to the server is UTF-8, see the server is garbled, it indicates that the server could not parse the data using UTF-8, using the Chinese operating system, the default encoding is GBK, Microsoft officials said so.

Reply:
Best to allow the server to check. The corresponding data is stored locally as utf8 format, open look is not normal. It is easy to see out.
Reply:
Try it with the middle two
[Request setHTTPMethod: @ "POST"];
[Request setValue: postLength forHTTPHeaderField: @ "Content-Length"];
[Request setValue: @ "application / x-www-form-urlencoded" forHTTPHeaderField: @ "Content-Type"];
[Request setHTTPBody: postData];

No comments:

Post a Comment