WKWebview发送POST请求

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod: @"POST"];
[request setHTTPBody:[@"id=12&name=Jhon" dataUsingEncoding: NSUTF8StringEncoding]];
[self.webView loadRequest:request];

以上方法经测试在iOS 8中无效,如果想兼容iOS 8可以考虑采用以下方法:
1.使用AFNetworking(或其他请求库)发送POST请求至服务器
2.获取服务器返回的HTML数据,并使用WKWebview加载

NSDictionary *param = @{@"id":@(12),
                        @"name":@"Jhon"};
[manager POST: urlString parameters:[CommonMethods newParams:parameters] progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSString *htmlStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        [self.wkWebview loadHTMLString:successInfo baseURL:nil];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
// manager 为 [AFHTTPSessionManager manager] 具体设置根据情况而定

你可能感兴趣的:(WKWebview发送POST请求)