4

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.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Roshni
  • 153
  • 2
  • 14

4 Answers4

4

Transport security has blocked a cleartext HTTP (http://) resource load since it is insecure, you need to add You have to set theNSAllowsArbitraryLoadskey toYESunderNSAppTransportSecuritydictionary in your.plist file`., and try see this link

Community
  • 1
  • 1
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
  • @Roshni - can you show ur url,if your url is wrong is not visible , can you updated the code – Anbu.Karthik Jul 27 '16 at 05:42
  • @Roshni - hide `NSString *postLength = [NSString stringWithFormat:@"%ld",[postData length]];` and ``[request setValue:postLength forHTTPHeaderField:@"Content-Length"];` try once – Anbu.Karthik Jul 27 '16 at 06:09
  • can you show what is `post` and at the same time see this link once for NSURL http://stackoverflow.com/questions/15291197/nsurl-always-returns-nil – Anbu.Karthik Jul 27 '16 at 06:20
  • authorize_user=1&state=MAHARASHTRA&f_name=xyzcccddd&amount=26750&mobileNo=9673870771&currency_code=INR&checksum_method=SHA256&checksum=e4b844fbee5c4ed69e2670c489&cardType=NB – Roshni Jul 27 '16 at 06:31
  • This is NSString post and also I checked the url. Its not going nil. – Roshni Jul 27 '16 at 06:31
1

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.

Varun P V
  • 1,092
  • 1
  • 12
  • 30
0

enter image description here

add like the picture,make sure your url is ok in safair

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
wg_hjl
  • 535
  • 3
  • 9
0

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.

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75