Since httpRequest body is ignored on WKWebView, I am trying to display a php page by fetching the data first, and displaying it.
func fetchData() {
URLSession.shared.dataTask(with: request) {(data, response, error) in
guard let data, let url = request.url else {
return
}
// pass the result to WKWebView
}.resume()
}
import Foundation
import SwiftUI
import WebKit
struct CustomWebView: UIViewRepresentable {
var url: URL
var data: Data
func makeUIView(context: Context) -> UIView {
return CustomUIWebView(url: url, data: data)
}
}
class CustomUIWebView: UIView {
let webView: WKWebView
init(url: URL,data:Data) {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
super.init(frame: .zero)
webView.load(data, mimeType: "text/html", characterEncodingName: "utf-8", baseURL: url)
addSubview(webView)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
webView.frame = bounds
}
The data contains the page that display several images, but it doesn't display any of the images in WKWebView.
Test and other components (such as checkmark button) have no problem, only images do.
Also, I confirmed it works fine on Safari.
So what is the issue here?
What am I doing wrong?
Post
Replies
Boosts
Views
Activity
I use this method.
webView.load(urlRequest)
but it seems the server receives empty httpBody.
I found threads about the simlar issue before iOS 11, but no recent one.
Is httpBody still ignored on iOS 17 and later?