ios wkwebView get请求增加header
现在工作有一个需求就是下载一个pdf,然后打开,但是我们iOS端因为种种原因并没有做下载文件的网络请求操作,所以只有用webview打开pdf。但是这个get请求,需要有header s串加密,所以只有改造了一下webvc这个类的load方法,
func loadRequest(_ request: URLRequest, headerS: String? = nil) {
self.headerS = headerS
var request = request
if !(headerS?.isEmpty ?? true) {
let m1 = ***加密参数1
let m2 = ***加密参数2
let post = m1 + headerS! + m2
guard let md5 = 加密方法 else { return }
request.addValue(md5, forHTTPHeaderField: "s")
}
var cookies = HTTPCookieStorage.shared.cookies ?? []
cookies.removeAll(where: {!$0.domain.hasSuffix(request.url?.host ?? "")})
request.allHTTPHeaderFields = (request.allHTTPHeaderFields ?? [:]).merging(HTTPCookie.requestHeaderFields(with: cookies), uniquingKeysWith: { (cookies0, cookies1) -> String in
var cookiesArray = [cookies0, cookies1]
cookiesArray.removeAll(where: {$0.isEmpty})
return cookiesArray.joined(separator: ";")
})
self.webView.load(request)
这样就可以在webview的请求中加入s串加密的东西了
网友评论