如何在AFNetworking 3.0中迁移? [英] How can I migrate in AFNetworking 3.0?
本文介绍了如何在AFNetworking 3.0中迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在迁移AFNetworking 3.0.我在AFNetworking中使用AFHTTPRequestOperation,但在最近的更新中已将其删除.我尝试了所有可能的解决方案.基本上,我需要使用Header发布JSON.我将我的NSDIctionary转换为JSON对象,然后将其添加为字符串.这是带有我的标头的示例JSON
I am migrating in AFNetworking 3.0. I am using AFHTTPRequestOperation in AFNetworking but it was removed in recent updates. I tried all the possible solution. Basically I need to post a JSON with Header. I convert my NSDIctionary into a JSON object then add it as string. Here is the sample JSON with Header of mine
RequestHeader={
"lname" : "sadhsdf",
"bday" : "2003-03-13",
"age" : "12",
"address" : "dsfhskdjgds",
"gender" : "M",
"cnumber" : "12312412",
"fname" : "sadhsdf",
"RequestType" : "userregistration",
"Email" : "sldjlkasd@sjdhflksdf.com",
"status" : "dsfhskdjgds",
"Password" : "123456"
}
RequestHeader是一个NSString,其余的是NSDictionary.
RequestHeader is an NSString and the rest are NSDictionary.
如何在AFNetworking 3.0中应用它?预先谢谢你.
How can I apply it in AFNetworking 3.0? Thank you in advance.
推荐答案
NSURL *url = [NSURL URLWithString:@"https://example.com/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
height, @"user[height]",
weight, @"user[weight]",
nil];
[httpClient postPath:@"/myobject" parameters:params
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"Request Successful, response '%@'", responseStr);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"[HTTPClient Error]: %@", error.localizedDescription);
}];
这篇关于如何在AFNetworking 3.0中迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文