Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

你好,请求成功后,需要获取allHeaderFields信息,要怎么做? #32

Open
liu521227 opened this issue Apr 13, 2017 · 4 comments

Comments

@liu521227
Copy link

你好,请求成功后,需要获取allHeaderFields信息,要怎么做?

@ZOYOOPlus
Copy link

我有封装了一层
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager.requestSerializer setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
AFJSONRequestSerializer * jsonRS = [AFJSONRequestSerializer  serializer];
NSMutableURLRequest *request = [jsonRS requestWithMethod:@"POST" URLString:urlString parameters:nil error:nil];

// 8be0ff56d7424b75b3982bda71f6b715 评论回复 taby2
// fd6ba3d31cdd47738497a3e6a9bb7016 获取评论
[request addValue:@"fd6ba3d31cdd47738497a3e6a9bb7016" forHTTPHeaderField:@"accessToken"];
[request addValue:@"222" forHTTPHeaderField:@"sign"];
[request addValue:@"3333" forHTTPHeaderField:@"version"];
[request addValue:@"06666" forHTTPHeaderField:@"deviceId"];
[request addValue:@"12312334" forHTTPHeaderField:@"timestamp"];
[request addValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];

NSLog(@" request :%@ ",request.allHTTPHeaderFields);
if (dic) {
    NSData *body = [NSJSONSerialization dataWithJSONObject:dic options:kNilOptions error:nil];
    [request setHTTPBody:body];
}

[manager POST:urlString parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
    
} progress:^(NSProgress * _Nonnull uploadProgress) {
    
} success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
    
    [[manager  dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {

// NSLog(@"responseObject%@",responseObject);
NSDictionary * dic = [(NSData *)responseObject objectFromJSONData];
// NSLog(@"responseObj: %@ ",dic);
getData(responseObject);
}] resume];

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    NSLog(@"%@",error);
    failureData(error);
}];

@liu521227
Copy link
Author

@ZOYOOPlus 你这是直接针对afn封装的吧。用XMNetworking请求成功后能不能直接获取服务器返回的allHeaderFields信息

@IAFung
Copy link

IAFung commented Apr 14, 2017

需要修改库的,加个参数就行了

@danfeng
Copy link

danfeng commented Feb 25, 2019

@IAFung 加什么参数?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants