It's not possible to perform a POST request with HTTPBody content in a WKWebView.

Originator:dick
Number:rdar://20464240 Date Originated:07-Apr-2015 12:49 PM
Status:Open Resolved:
Product:iOS SDK Product Version:iOS 8.2
Classification:Serious Bug Reproducible:Always
 
Summary:
WKWebView will empty the HTTPBody of a POST URLRequest.
Creating a URLRequest with a HTTPBody and using this request to load content in the WKWebView. Will result in the WKWebView emptying the HTTPBody.

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:`.
- Track the request that is going out with Charles for instance or use the NSURLProtocol to see the HTTPBody of the request.

Or use this code snippet:

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    WKWebView *webView = [WKWebView new];
    webView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:webView];
    
    NSDictionary *views = @{@"webView": webView};
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[webView]|" options:0 metrics:nil views:views]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[webView]|" options:0 metrics:nil views:views]];
    
    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]];
    urlRequest.HTTPMethod = @"POST";
    urlRequest.HTTPBody = [@"test" dataUsingEncoding:NSUTF8StringEncoding];
    [webView loadRequest:urlRequest];
}

Expected Results:
The request going out to the www.apple.com server will not contain the HTTPBody. This works in UIWebView.

Actual Results:
HTTPBody is nil.

Version:
iOS 8.2 (12D508)

Notes:


Configuration:
iPad air, iPhone 6, iOS simulators

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!