Reputation: 153
I have a html page and on submit button click I need to call the Payment gateway URL.
I am using NSMutableURLRequest
and post data is passed and I am calling the URL using
Please find below code:
NSDictionary *parameters = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:currency_code,apikey,merchant_id,checksum_method,authorize_user,ip_address,hash,NB, nil] forKeys:[NSArray arrayWithObjects:@"currency_code",@"apikey",@"merchant_id",@"checksum_method",@"authorize_user",@"ip_address",@"checksum",@"cardType", nil]];
__block NSString *post = @"";
[parameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
if ([post isEqualToString:@""]) {
post = [NSString stringWithFormat:@"%@=%@",key,obj];
} else {
post = [NSString stringWithFormat:@"%@&%@=%@",post,key,obj];
}
}];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%ld",[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://pay.sandbox.shmart.in/pay_merchant/js"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[webview loadRequest:request];
The webViewDidFinishLoad
is also called but it is showing me a blank white screen.
Any idea on what is the problem.
Upvotes: 4
Views: 3498
Reputation: 1233
I have faced the same issue and fixed it by removing the space and unwanted characters from the URL.
If you are trying to load an HTTP URL only, please check and enable the AllowArbitaryLoad In the App Transport Security Settings in the info.plist. You can refer to the following link.
Transport security has blocked a cleartext HTTP
If you are using the https URL, please make sure the URL is loading fine in the Safari and as well as in the Chrome browser responsive mode.
Sometimes, the website will load the response URL in iFrame. so please check that pass the correct URL.
Also, print the URL before you pass to the UIWebView, sometimes it should have space and as well as &
. so remove the same and pass it in the WebView.
serviceBookingUrl = [NSURLRequest requestWithURL: [NSURL URLWithString:[websiteURL stringByReplacingOccurrencesOfString:@"&" withString:@"&"]]];
[PrimaryWebView loadRequest: serviceBookingUrl];
where websiteURL is the website URL.
Upvotes: 1
Reputation: 545
add like the picture,make sure your url is ok in safair
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Upvotes: 0
Reputation: 27448
Your code should be like,
UIWebView *tempWebview = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 300, 500)];
[self.view addSubview:tempWebview];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
[tempWebview loadRequest:request];
Your url must support mobile web browser
So check your url and parameters are valid and you have made valid request.
Upvotes: 0
Reputation: 82766
Transport security has blocked a cleartext HTTP (http://) resource load since it is insecure, you need to add You have to set the
NSAllowsArbitraryLoadskey to
YESunder
NSAppTransportSecuritydictionary in your
.plist file`., and try see this link
Upvotes: 4