If the request is a single webview or request, implement nsurlconnectiondelegate directly in the requested file H and add the following two methods in M:
C code
- -(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];
- }
-(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];}
The above method is very uncomfortable is the place of each request to add.
If the project uses the THREE20, directly modify the "TTREQUESTLOADER.M" can be, the file itself has been implemented nsurlconnectiondelegate,
Modified as follows, only change this one place is OK, everywhere is available.
C code
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- -(void) connection: (Nsurlconnection *) connection
- Didreceiveauthenticationchallenge: (Nsurlauthenticationchallenge *) challenge{
- //Modify
- 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];
- }
- Add to
- -(BOOL) connection: (Nsurlconnection *) connection canauthenticateagainstprotectionspace: (Nsurlprotectionspace * ) Protectionspace {
- return [Protectionspace.authenticationmethod isequaltostring:nsurlauthenticationmethodservertrust];
- }
-(void) Connection: (Nsurlconnection *) Connectiondidreceiveauthenticationchallenge: (Nsurlauthenticationchallenge *) challenge{//Modify 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];} Add-(BOOL) connection: (Nsurlconnection *) connection canauthenticateagainstprotectionspace: (Nsurlprotectionspace * ) Protectionspace {return [Protectionspace.authenticationmethod isequaltostring: Nsurlauthenticationmethodservertrust];}
iOS Project bypass certificate access HTTPS program