@
snail1988 对,防止抓包,但是我写了 ssl-pinning 的代码测试过还是可以抓包的。
``` Objective-c
+ (AFSecurityPolicy*)customSecurityPolicy
{
NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"https12" ofType:@"cer"];
NSData *certData = [NSData dataWithContentsOfFile:cerPath];
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
securityPolicy.allowInvalidCertificates = NO;
securityPolicy.validatesDomainName = YES;
securityPolicy.pinnedCertificates = @[certData];
return securityPolicy;
}
+ (void)postUploadWithUrl:(NSString *)urlStr para:(NSDictionary *)para name:(NSString *)name fileData:(NSData *)fileData fileName:(NSString *)fileName fileType:(NSString *)fileType success:(void (^)(id responseObject))success fail:(void (^)(void))fail
{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.securityPolicy = [AFNetPackage customSecurityPolicy];
[manager POST:urlStr parameters:para constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
[formData appendPartWithFileData:fileData name:name fileName:fileName mimeType:fileType];
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
if (success) {
success(responseObject);
}
} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
if (fail) {
fail();
}
}];
}
```