ios - AFNetworking 迁移 - 替代 HTTPRequestOperationWithRequest
问题描述
我正在将一个旧项目迁移到目标 c 中的最新 AFNetworking pod。我不确定如何在最新的 AFNetworking 中管理添加操作,也没有找到任何相关文章。
+ (void)uploadXMLDocumentWithUrl:(NSString*)serviceURL
xmlFileData:(NSData *)xmlData
withSuccessBlock:(void (^)(id response, NSDictionary* headers))successBlock
withErrorBlock:(void (^)(NSError* error, NSDictionary* headers, id responseObject))errorBlock
{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFXMLParserResponseSerializer serializer];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serviceURL]];
[request setHTTPBody: xmlData];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/xml" forHTTPHeaderField:@"Accept"];
NSOperation *operation = [manager HTTPRequestOperationWithRequest:request success:^(NSURLSessionTask *operation, id responseObject) {
NSDictionary* headersCollection = [[(NSDictionary*)operation valueForKey:@"response"] valueForKey:@"allHeaderFields"];
NSMutableDictionary* headers = [headersCollection mutableCopy];
headers[@"statusCode"] = [NSNumber numberWithInteger:operation.response.statusCode];
successBlock(responseObject, headers);
}
failure:^(AFHTTPRequestOperation* operation, NSError* error) {
NSDictionary* headersCollection = [[(NSDictionary*)operation valueForKey:@"response"] valueForKey:@"allHeaderFields"];
NSMutableDictionary* headers = [headersCollection mutableCopy];
headers[@"statusCode"] = [NSNumber numberWithInteger:operation.response.statusCode];
errorBlock(error, headers, operation.responseObject);
}];
[manager.operationQueue addOperation:operation];
}
我知道AFHTTPRequestOperationManager
已迁移到,AFHTTPSessionManager
但我不了解如何迁移HTTPRequestOperationWithRequest:request
。非常感谢任何帮助。谢谢
解决方案
推荐阅读
- php - do_shortcode:引号之间带有变量的打开和关闭标记
- c# - CS50542 和 CS0103 adter 使用代码转换器将包含 wpf 控件的 vb 项目转换为 c#
- mysql - MYSQL 在过去 10 分钟内删除每个 id、标题的重复行
- python - NameError: name 'spark' is not defined,如何解决?
- javascript - MERN 无法部署到 heroku
- kotlin - Kotlin ConflatedBroadcastChannel.offer() 不起作用?
- python - 出现问题时继续扫描另一个站点
- python-3.x - Bert 预训练模型每次给出随机输出
- javascript - 我想在滚动时显示 div 获取 TypeError: $ is not a function?
- javascript - Greasemonkey:如何删除随机 url 部分?