0

我有一个 Webview,我首先在其中加载一个 URL,该 URL 将自动重定向到https://secure.authorize.net/gateway/transact.dll

但是委托功能

两者都不

- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;

也不

-(NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse;

打电话。所以我只有一个空白页。请帮助我。

我正在使用这个函数来加载我的初始 URL

 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];
}
4

1 回答 1

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];

}

于 2012-11-02T09:59:52.447 回答