问题描述
- AFNetworking head 怎么设置 求帮助! 2C
- POST登录后我需要保存一个字段,如下代码所示
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:@""zhangsan"" @""loginId"" @""123"" @""passwd"" nil]; [manager POST:encodeUrl parameters:parameters success:^(AFHTTPRequestOperation *operation id responseObject) {//数据获取成功 if ([[responseObject objectForKey:@""result""] integerValue] == 1) { NSArray *array = [[operation.response.allHeaderFields objectForKey:@""Set-Cookie""] componentsSeparatedByString:@"";""]; if (array.count > 0) { NSFileManager *fm = [NSFileManager defaultManager]; NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory NSUserDomainMask YES); NSString *filePath = [path objectAtIndex:0]; NSString *plistPath = [filePath stringByAppendingPathComponent:@""userInfo.plist""]; if ([fm fileExistsAtPath:plistPath]) { [fm removeItemAtPath:plistPath error:nil]; } [[appDelegate userInfo] setValue:[array objectAtIndex:0] forKey:@""JSESSIONID""]; [fm createFileAtPath:plistPath contents:nil attributes:nil]; [[appDelegate userInfo] writeToFile:plistPath atomically:YES]; [self.navigationController popViewControllerAnimated:YES]; //返回首页 [appDelegate selected:0]; }else { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@""登录失败,请重试!"" delegate:nil cancelButtonTitle:@""确定"" otherButtonTitles:nil]; [alertView show]; } } } failure:^(AFHTTPRequestOperation *operation NSError *error) { }];
我用另一个接口获取用户信息时需要用到保存的这个字段,但是不知道怎么才能加进去,我用如下方法加入后总是提示失败
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; [manager.requestSerializer setValue:@""application/json"" forHTTPHeaderField:@""Accept""]; [manager.requestSerializer setValue:@""application/json;charset=utf-8"" forHTTPHeaderField:@""Content-Type""]; [manager.requestSerializer setValue:[[appDelegate userInfo] objectForKey:@""JSESSIONID""] forHTTPHeaderField:@""Set-Cookie""];
解决方案
你这个是不是涉及到网页的cookie 你是在本地操作到webView上做操作吗
时间: 2024-11-03 10:32:17