国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ios項目繞過證書訪問https程序

2019-11-14 19:53:36
字體:
來源:轉載
供稿:網友

如果是單個的webview或者request請求,在請求的文件h中直接實現NSURLConnectionDelegate,并在m中添加下列實現下列兩個方法:

 

 

C代碼 復制代碼 收藏代碼
  1. - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstPRotectionSpace:(NSURLProtectionSpace *)protectionSpace {  
  2.     return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];  
  3. }  
  4.   
  5. - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {  
  6.     if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])  
  7.         //if ([trustedHosts containsObject:challenge.protectionSpace.host])  
  8.             [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]   
  9.                  forAuthenticationChallenge:challenge];    
  10.     [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];  
  11. }  
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {    return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];}- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])        //if ([trustedHosts containsObject:challenge.protectionSpace.host])            [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]                  forAuthenticationChallenge:challenge];      [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];}

 上述方法很不爽的是每個請求的地方都要加。

 

如果項目中用到了three20,直接修改“TTRequestLoader.m”即可,這個文件本身就已經實現了NSURLConnectionDelegate,

 

修改如下,只改這一個地方就行,處處可用。

 

 

C代碼 復制代碼 收藏代碼
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////  
  2. - (void)connection:(NSURLConnection *)connection  
  3. didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{  
  4.     //修改  
  5.     if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])  
  6.         [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];  
  7.     [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];  
  8.       
  9.     TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"  RECEIVED AUTH CHALLENGE LOADING %@ ", _urlPath);  
  10.     [_queue loader:self didReceiveAuthenticationChallenge:challenge];  
  11. }  
  12.   
  13. //添加  
  14. - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {  
  15.     return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];  
  16. }  
///////////////////////////////////////////////////////////////////////////////////////////////////- (void)connection:(NSURLConnection *)connectiondidReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{    //修改    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])        [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];    [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];        TTDCONDITIONLOG(TTDFLAG_URLREQUEST, @"  RECEIVED AUTH CHALLENGE LOADING %@ ", _urlPath);    [_queue loader:self didReceiveAuthenticationChallenge:challenge];}//添加- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {    return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];}

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东城区| 襄樊市| 金秀| 威信县| 绥江县| 象山县| 宁武县| 南川市| 南涧| 龙南县| 南溪县| 原平市| 鄂托克前旗| 西安市| 永登县| 平昌县| 麦盖提县| 三穗县| 吉水县| 镇宁| 台山市| 沽源县| 富宁县| 奉化市| 临高县| 抚宁县| 南通市| 民乐县| 黑河市| 荆州市| 武平县| 富阳市| 会东县| 内黄县| 门头沟区| 鹤庆县| 曲水县| 图木舒克市| 柳江县| 桓仁| 新疆|