iOS内で、次のようにhttpリクエストを作成しています。
NSURL* url = [ NSURL URLWithString:[ NSString stringWithFormat: @"%@%@", [ HPSWebService getBaseURL ], @"Sync/PushObject"] ];
// 'request' is defined within the base class and is set here to the class-specific server url
request = [[NSMutableURLRequest alloc] initWithURL:url];
NSString* jsonRequest = [NSString stringWithFormat: @"{\"collection\":\"responses\",\"id\":\"%@\",\"objectjson\":%@}",response.id,response.json];
NSLog(@"HPSPushResponsesWebService jsonRequest = %@",jsonRequest);
NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:self.contentEncoding forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody: requestData];
NSLogの出力は次のとおりです。
2012-10-23 15:45:51.543 HPS [12523:707] HPSPushResponsesWebService jsonRequest = {"collection": "responses"、 "id": "ZBZiaa43QciMSlMCp0Vtyw =="、 "objectjson":{"_ id": "{\ "$ binary \":\ "ZBZiaa43QciMSlMCp0Vtyw == \"、\ "$ type \":\ "03 \"} "、" _ user ":" Eddie Freshman "、" _ lastmodifieddatelocalutc ":" 2012-10-23 14: 45:39 "、" Fav Car ":[" Other:Me√´zoom "]、" _ formid ":" {\" $ binary \":\ "OCDI9VNGStmN8GbOLSevtA == \"、\ "$ type \":\ "03 \"} "、"フォローアップが必要ですか? ":[]、" _ contactid ":" {\ "$ binary \":\ "+ 3144XhxQzCNzWKfqXCHyg == \"、\ "$ type \":\ "03 \ "}"}}
JSONデータに特殊文字(ウムラウトなど)が含まれるまでは、すべて正常に機能します。これが発生すると、コンテンツの長さは実際には本来より1文字短くなります。この例では、umlat(e)charが√´(Fav Car文字列の近く)に変換されています。
コンテンツの長さがhttpリクエスト内で正しく設定されるように、これをどのようにコーディングする必要がありますか?
ありがとう