Reputation: 5230
I have a Webview in which I first load an URL, which will automatically redirect to https://secure.authorize.net/gateway/transact.dll.
But the delegate functions
neither
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
nor
-(NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse;
calling. So I got only a blank page. Please help me in this.
I am using this function to load my Initial 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];
}
Upvotes: 0
Views: 618
Reputation: 5230
I fixed this by resending the request whenever the server failed to load.
- (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");
}
And now the delegate functions are called. I can trust the server here.
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
NSURLProtectionSpace *space = [challenge protectionSpace];
[space serverTrust];
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
Upvotes: 1