我正在使用AFNetworking与我的JSON API通信。一切正常,除了用德语元音发送请求(即äöüi.e.)。
我使用的是共享实例
+(LFMessaging*)shared
{
static LFMessaging *sharedInstance = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}为了发送数据,我使用了AFHTTPClient的一个子类和这个方法:
[parameters setValue:cmd forKey:@"cmd"];
NSMutableURLRequest *apiRequest =
[self multipartFormRequestWithMethod:@"POST"
path:[NSString stringWithFormat:@"http://%@%@", _domain, _target]
parameters:(NSDictionary*)parameters
constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
//TODO: attach file if needed
}];
AFJSONRequestOperation* operation = [[AFJSONRequestOperation alloc] initWithRequest: apiRequest];
operation.JSONReadingOptions = NSJSONReadingMutableContainers;
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
...就在一个带有德国元音符号的参数传递时,api似乎要崩溃了。服务器未收到正确的字符串。
如果服务器在json结果中发送umlauts,那么一切都是正常的。
发布于 2013-02-23 20:39:50
self.stringEncoding = NSUTF8StringEncoding;解决了问题
https://stackoverflow.com/questions/15032116
复制相似问题