POST request not working with HTTPBody content in WKWebView

Area: WebKit

Summary: Create a URLRequest with a HTTPBody and using this request to load content in the WKWebView.

In our code, we are doing this for making payment using credit card via Payfort, code was working fine with UIWebView

but when we replaced UIWebView with WKWebView, then it displays error in the web view.


Steps to Reproduce:

- Create WKWebView.

- Create a NSMutableURLRequest.

- Set the HTTPMethod of the URLRequest to POST.

- Set some data to the HTTPBody of the URLRequest.

- Make WKWebView perform the URLRequest by `loadRequest:`


NSMutableURLRequest *tokenizationRequest = [NSMutableURLRequest requestWithURL:requestURL];

//request URL = @"https://sbcheckout.payfort.com/FortAPI/paymentPage";

[tokenizationRequest setHTTPMethod:@"POST"];

[tokenizationRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];

[tokenizationRequest setHTTPBody:[requestBody dataUsingEncoding:NSUTF8StringEncoding]];

/*

//requestBody is defined below

access_code=XX&language=en&merchant_identifier=XX&merchant_reference=33&return_url=XX.com&service_command=XX&expiry_date=2105&card_number=4005500000000001&card_security_code=123&card_holder_name=XX&remember_me=YES&signature=XX

Note: Actual value of params has been replaced with XX and 33

*/

[[NSURLCache sharedURLCache] removeCachedResponseForRequest:tokenizationRequest];


WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];

self.paymentWebView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration];

self.paymentWebView.translatesAutoresizingMaskIntoConstraints = NO;

self.paymentWebView.UIDelegate = self;

self.paymentWebView.navigationDelegate = self;

self.paymentWebView.scrollView.alwaysBounceVertical = NO;

self.paymentWebView.scrollView.alwaysBounceHorizontal = NO;

[self.view addSubview:self.paymentWebView];

[self.paymentWebView addConstraintToBindAllSidesWithSuperView:self.view withMargin:0];

[self.paymentWebView loadRequest:tokenizationRequest];


Expected Results:

In didFinishNavigation delegate method, we should get the destination URL but, it is providing source URL:


URL Should be like:

https://XX.com/?response_code=33&card_number=400550******0001&card_holder_name=XX&signature=XX&merchant_identifier=XX&access_code=XX&expiry_date=2105&language=en&response_message=Invalid+card+number&service_command=XX&merchant_reference=2000042928&return_url=http:://XX.com&remember_me=YES&status=00


Actual Results:

URL we are getting is :

https://sbcheckout.payfort.com/FortAPI/paymentPage?S=4&#Again-No-back-button


Configuration:

XCode 10

Delpoyment target : iOS 9 and above

Tested on : iPhone (iOS 12), iPad (ios 10.3.3)


For more details, kindly refer:

https://bugreport.apple.com/web/?problemID=45335442


Other references:

https://forums.developer.apple.com/thread/18952

https://forums.developer.apple.com/thread/108385

Replies

....