星五博客

AFNetworking3初体验(get json)

NSURL *URL = [NSURLURLWithString:@"http://localhost:8833/info"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManagermanager];
    //下面这句不加,会提示这个错误:NSLocalizedDescription=Request failed: unacceptable content-type: text/plain
    manager.responseSerializer.acceptableContentTypes=[manager.responseSerializer.acceptableContentTypessetByAddingObject:@"text/plain"];
    [manager GET:URL.absoluteStringparameters:nilsuccess:^(NSURLSessionTask *task, id responseObject) {
        NSLog(@"JSON: %@", responseObject);
    } failure:^(NSURLSessionTask *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];


IOS