我有一个Webview,我首先加载一个网址,该网址会自动重定向到https://secure.authorize.net/gateway/transact.dll。
但代表职能
既不是
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
,也不
-(NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse;
呼叫。所以我只得到一个空白页面。 请帮助我。
我正在使用此功能加载我的初始网址
myReq=[NSURLRequest requestWithURL:[NSURL URLWithString:myStr]];
NSURLConnection *myConn=[NSURLConnection connectionWithRequest:myReq delegate:self];
if(myConn){
webdata = [[NSMutableData alloc] init];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[webdata appendData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
[[myWebView mainFrame] loadData:webdata MIMEType: @"text/html" textEncodingName: @"UTF-8" baseURL:nil];
}
答案 0 :(得分:1)
我通过在服务器加载失败时重新发送请求来修复此问题。
- (void)webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame{
NSLog(@"%@", [error description]);
NSURLConnection *myConnn=[NSURLConnection connectionWithRequest:[[[sender mainFrame] provisionalDataSource] request] delegate:self];
if(myConnn)
NSLog(@"I got it");
}
现在调用委托函数。我可以信任服务器。
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
NSURLProtectionSpace *space = [challenge protectionSpace];
[space serverTrust];
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}