class HttpHeaderInterceptor implements rcp.Interceptor {
async intercept(context: rcp.RequestContext, next: rcp.RequestHandler): Promise<rcp.Response> {
const url = context.request.url.toString();
logger.debug("拦截 url:" + context.request.url.toString());
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION |
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA;
let bundleData = await bundleManager.getBundleInfoForSelf(bundleFlags)
context.request.headers!["osVersion"] = bundleData["versionName"];
context.request.headers!["deviceid"] = deviceinfo.ODID;
context.request.headers!["deviceModel"] = deviceinfo.distributionOSVersion;
context.request.headers!["appName"] = "qx_harmony";
logger.debug("最终请求:" + context.request.url.toString());
const promise = next.handle(context);
promise.then((resp) => {
resp.statusCode;
});
return promise;
}
}
在拦截器中增加header参数get请求报错,检查context.request.headers为空post可以。如果要get请求在拦截中增加header该如何处理?
可以尝试将:
换成: