|
|
@@ -16,6 +16,7 @@
|
|
|
NSString *mCloudService;
|
|
|
//NSString *mRequstAPI;
|
|
|
|
|
|
+ AFHTTPSessionManager *managerNAS;
|
|
|
}
|
|
|
|
|
|
@end
|
|
|
@@ -108,7 +109,7 @@ static netWorkManager *Game_NetWorkShareInstance = nil;
|
|
|
|
|
|
if ([mCloudService rangeOfString:@"https"].location != NSNotFound)
|
|
|
{
|
|
|
- //[manager setSecurityPolicy:[self customSecurityPolicy]];
|
|
|
+ [manager setSecurityPolicy:[self customSecurityPolicy]];
|
|
|
}
|
|
|
|
|
|
// 客户端是否信任非法证书
|
|
|
@@ -126,6 +127,82 @@ static netWorkManager *Game_NetWorkShareInstance = nil;
|
|
|
|
|
|
}
|
|
|
|
|
|
+- (void)setAFHTTPSessionManagerFunBy:(NSInteger)tcpPort
|
|
|
+{
|
|
|
+ NSString *ip = @"127.0.0.1";
|
|
|
+ NSNumber *proxyPort = [NSNumber numberWithInteger:tcpPort];
|
|
|
+ NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
|
|
|
+ config.connectionProxyDictionary = @
|
|
|
+ {
|
|
|
+ @"HTTPEnable":@YES,
|
|
|
+ @"HTTPProxy" : ip,
|
|
|
+ @"HTTPPort" : proxyPort,
|
|
|
+ @"HTTPSEnable":@YES,
|
|
|
+ @"HTTPSProxy": ip,
|
|
|
+ @"HTTPSPort": proxyPort
|
|
|
+ };
|
|
|
+
|
|
|
+ managerNAS = [[AFHTTPSessionManager alloc] initWithBaseURL:nil sessionConfiguration:config];
|
|
|
+
|
|
|
+ managerNAS.requestSerializer = [AFJSONRequestSerializer serializer];
|
|
|
+ managerNAS.responseSerializer = [AFJSONResponseSerializer serializer];
|
|
|
+ [managerNAS.requestSerializer setHTTPShouldHandleCookies:NO];
|
|
|
+ [managerNAS.requestSerializer setHTTPShouldUsePipelining:NO];
|
|
|
+ managerNAS.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", @"text/plain",@"application/xml",@"image/png", @"audio/aac", @"text/x-vcard",nil];
|
|
|
+
|
|
|
+ managerNAS.requestSerializer.HTTPMethodsEncodingParametersInURI = [NSSet setWithObjects:@"GET", @"HEAD", nil];
|
|
|
+
|
|
|
+ if ([NASService rangeOfString:@"https"].location != NSNotFound)
|
|
|
+ {
|
|
|
+ [managerNAS setSecurityPolicy:[self customSecurityPolicy]];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#pragma - mark 证书相关
|
|
|
+- (AFSecurityPolicy*)customSecurityPolicy
|
|
|
+{
|
|
|
+// // /先导入证书
|
|
|
+// NSString *cerName = @"newrelease";
|
|
|
+// if ([@"https://client.phone.androidscloud.com" isEqualToString:CloudService])
|
|
|
+// {
|
|
|
+// cerName = @"newrelease";
|
|
|
+// }
|
|
|
+// else if ([@"https://prese.phone.androidscloud.com" isEqualToString:CloudService])
|
|
|
+// {
|
|
|
+// cerName = @"newrelease";
|
|
|
+// }
|
|
|
+// NSString *cerPath = [[NSBundle mainBundle] pathForResource:cerName ofType:@"cer"];//证书的路径
|
|
|
+// NSData *certData = [NSData dataWithContentsOfFile:cerPath];
|
|
|
+
|
|
|
+ // AFSSLPinningModeCertificate 使用证书验证模式、、、//AFSSLPinningModeNone 不使用SSLPinning //AFSSLPinningModeCertificate 使用SSLPinning
|
|
|
+ AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
|
|
|
+
|
|
|
+// if ([@"https://test.androidscloud.com" isEqualToString:CloudService])
|
|
|
+// {
|
|
|
+// securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
|
|
|
+// }
|
|
|
+// else if ([@"https://pre.androidscloud.com" isEqualToString:CloudService])
|
|
|
+// {
|
|
|
+// securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
|
|
|
+// }
|
|
|
+// else if ([@"https://a.androidscloud.com" isEqualToString:CloudService])
|
|
|
+// {
|
|
|
+// securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
|
|
|
+// }
|
|
|
+
|
|
|
+ // allowInvalidCertificates 是否允许无效证书(也就是自建的证书),默认为NO
|
|
|
+ // 如果是需要验证自建证书,需要设置为YES
|
|
|
+ securityPolicy.allowInvalidCertificates = NO;
|
|
|
+ //validatesDomainName 是否需要验证域名,默认为YES;
|
|
|
+ //假如证书的域名与你请求的域名不一致,需把该项设置为NO;如设成NO的话,即服务器使用其他可信任机构颁发的证书,也可以建立连接,这个非常危险,建议打开。
|
|
|
+ //置为NO,主要用于这种情况:客户端请求的是子域名,而证书上的是另外一个域名。因为SSL证书上的域名是独立的,假如证书上注册的域名是www.google.com,那么mail.google.com是无法验证通过的;当然,有钱可以注册通配符的域名*.google.com,但这个还是比较贵的。
|
|
|
+ //如置为NO,建议自己添加对应域名的校验逻辑。
|
|
|
+ securityPolicy.validatesDomainName = YES;
|
|
|
+
|
|
|
+// securityPolicy.pinnedCertificates = [[NSSet alloc] initWithObjects:certData, nil];
|
|
|
+
|
|
|
+ return securityPolicy;
|
|
|
+}
|
|
|
|
|
|
#pragma - mark 证书相关
|
|
|
//- (AFSecurityPolicy*)customSecurityPolicy
|
|
|
@@ -360,7 +437,8 @@ static netWorkManager *Game_NetWorkShareInstance = nil;
|
|
|
NSString *url = [NSString stringWithFormat:@"%@/%@",curServer,code];
|
|
|
HLog(@"地址:%@ \n接口名称:%@,\n 参数:%@\n",url,code,dict);
|
|
|
|
|
|
- [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
|
|
+ //managerNAS manager
|
|
|
+ [managerNAS.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
|
|
|
|
|
if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable)
|
|
|
{// 无网络状态
|
|
|
@@ -371,6 +449,7 @@ static netWorkManager *Game_NetWorkShareInstance = nil;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ //managerNAS manager
|
|
|
[manager GET:url parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
|
|
|
HLog(@"接口名称:%@ 接口返回:%@,\n ",code,responseObject);
|