一、ASI请求,http换成https
self.request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:getAccessTokenUrl]];
[self.request setValidatesSecureCertificate:NO];//设置为NO
//[self.request setSslSecurityLevel:(CFStringRef*)kCFStreamSocketSecurityLevelTLSv1];//设置安全等级,默认不用设置
二、WebView,http换成https
- (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
//加入以下代码if (!_authenticated && [requestUrl hasPrefix:@"https://"]) {
_authenticated =NO;
_urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
_request = request;
[_urlConnection start];
return YES;
}
}
//修改以下三个方法
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge previousFailureCount] == 0)
{
_authenticated = YES;
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
[challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
} else
{
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
// remake a webview call now that authentication has passed ok.
_authenticated = YES;
[self.webView loadRequest:_request]; // self.webView替换成自己的webview
// Cancel the URL connection otherwise we double up (webview + url connection, same url = no good!)
[_urlConnection cancel];
[self refreshWithMJComplete];
[self stopLoading];
}
// We use this method is to accept an untrusted site which unfortunately we need to do, as our PVM servers are self signed.
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}