我正在AFNetworking 3.0中进行迁移。我在AFNetworking中使用AFHTTPRequestOperation,但在最近的更新中已将其删除。我尝试了所有可能的解决方案。基本上,我需要使用Header发布JSON。我将我的NSDIctionary转换为JSON对象,然后将其添加为字符串。这是带有我的标头的示例JSON
RequestHeader={
"lname" : "sadhsdf",
"bday" : "2003-03-13",
"age" : "12",
"address" : "dsfhskdjgds",
"gender" : "M",
"cnumber" : "12312412",
"fname" : "sadhsdf",
"RequestType" : "userregistration",
"Email" : "[email protected]",
"status" : "dsfhskdjgds",
"Password" : "123456"
}
RequestHeader是一个NSString,其余的都是NSDictionary。
如何在AFNetworking 3.0中应用它?先感谢您。
最佳答案
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);
}];
关于ios - 如何在AFNetworking 3.0中迁移?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35971828/