Encoding 阿夫洛茨酒店

Encoding 阿夫洛茨酒店,encoding,afnetworking,Encoding,Afnetworking,我正在使用AFNetworking与JSON API通信。除了用德国umlauts(即äöüß)发送请求外,一切都很好 我正在使用一个共享实例 +(LFMessaging*)shared { static LFMessaging *sharedInstance = nil; static dispatch_once_t oncePredicate; dispatch_once(&oncePredicate, ^{ sharedInstance =

我正在使用AFNetworking与JSON API通信。除了用德国umlauts(即äöüß)发送请求外,一切都很好

我正在使用一个共享实例

+(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) {
...
[参数设置值:cmd forKey:@“cmd”];
NSMutableURLRequest*APIRQUEST=
[self multipartFormRequestWithMethod:@“POST”
路径:[NSString stringWithFormat:@“http://%@%@”,\u域,\u目标]
参数:(NSDictionary*)参数
构造体WithBlock:^(id formData){
//TODO:如果需要,请附加文件
}];
AFJSONRequestOperation*操作=[[AFJSONRequestOperation alloc]initWithRequest:apiRequest];
operation.JSONReadingOptions=NSJSONReadingMutableContainers;
[操作setCompletionBlockWithSuccess:^(AFHTTPRequestOperation*操作,id响应对象){
...
当一个带有德国umlaut ist的参数通过时,api似乎中断了。服务器没有收到正确的字符串

如果服务器以json结果发送UMLAUT,则一切正常

self.stringEncoding = NSUTF8StringEncoding;
解决了这个问题