HarmonyOS Web拦截网页动态添加请求头
动态拦截请求,在满足条件时动态给请求加请求头,按官方方法实现,发现白屏,网页无法打开
.onInterceptRequest((event) => {
if (event) {
console.log('url:' + event.request.getRequestUrl());
let url: string = event.request.getRequestUrl();
//this.responseWeb.setResponseIsReady(false);
if (url.includes("jtg.com")) {
if (!this.hasCustomHeader.has(url)) {
PreferencesUtil.getUser().then(user => {
if (user.ssoValue) {
const cookie: string = `Cookie: ${user.ssoName}=${user.ssoValue}`
Logger.info(TAG, `url:${url},PreferencesUtil:${cookie}`)
webview.WebCookieManager.configCookieSync(url, cookie);
this.hasCustomHeader.add((url))
let headers: Header = {
headerKey: user.ssoName,
headerValue: user.ssoValue
}
this.heads.push(headers)
this.responseWeb.setResponseHeader(this.heads);
this.responseWeb.setResponseIsReady(true);
Logger.info(TAG, `url:${url},setResponseIsReady:${cookie}`)
} else {
webview.WebCookieManager.clearAllCookies()
}
})
}
}
}
this.responseWeb.setResponseIsReady(false);
return this.responseWeb;
})
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
HarmonyOS
赞
收藏 0
回答 1
相关问题
HarmonyOS Video 怎么添加请求头?
872浏览 • 2回复 待解决
HarmonyOS web拦截网络请求
778浏览 • 1回复 待解决
HarmonyOS web组件怎么拦截请求
1133浏览 • 1回复 待解决
web组件如何设置请求头
933浏览 • 1回复 待解决
HarmonyOS webview请求资源文件拦截器修改请求头信息
683浏览 • 1回复 待解决
HarmonyOS Web组件是否支持修改在线h5网页的请求头
936浏览 • 1回复 待解决
HarmonyOS Web组件如何附加请求头header
887浏览 • 1回复 待解决
HarmonyOS @ohos.net.http 如何添加请求拦截和响应拦截
635浏览 • 1回复 待解决
HarmonyOS Web组件实现异步的请求拦截
649浏览 • 1回复 待解决
Web组件拦截页面请求响应
1731浏览 • 1回复 待解决
HarmonyOS 如何在post请求头添加自定义cookie
542浏览 • 1回复 待解决
HarmonyOS Web组件如何拦截特殊url请求?
1323浏览 • 1回复 待解决
需要加载网页的时候添加请求头,在这个onLoadIntercept 中获取不到header,这是什么原因呢?
922浏览 • 1回复 待解决
HarmonyOS 使用downloadFile接口时,是否可在请求头添加cookie
906浏览 • 1回复 待解决
HarmonyOS webview使用问题:如何拦截url并添加参数,如何添加请求header
1125浏览 • 1回复 待解决
HarmonyOS web如何拦截到页面字体资源请求
553浏览 • 1回复 待解决
HarmonyOS Http网络请求框架支持添加拦截器吗
1118浏览 • 1回复 待解决
HarmonyOS 怎么给web组件的请求添加header
1201浏览 • 1回复 待解决
HarmonyOS web页面跳转和拦截Web组件发起的网络请求的区别
746浏览 • 1回复 待解决
HarmonyOS 请求头信息修改
709浏览 • 1回复 待解决
HarmonyOS 请求头设置cookie
1075浏览 • 1回复 待解决
HarmonyOS Web加载网页白屏
1356浏览 • 1回复 待解决
HarmonyOS Http请求头问题咨询
1128浏览 • 1回复 待解决
HarmonyOS WebView拦截网络请求
1307浏览 • 1回复 待解决
HarmonyOS view动态添加
819浏览 • 1回复 待解决
请检查是否加了以下权限
添加请求头: