转载:https://blog.csdn.net/wdw984/article/details/85275289
1.首先要让我们自己的CefClient这个类公有继承CefRequestHandler
2.添加Request事件构造函数
CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE{ return this; }
3.然后重写父类的OnBeforeBrowse和OnBeforeResourceLoad两个方法
在.h文件中添加函数声名
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, bool user_gesture, bool is_redirect) OVERRIDE; virtual ReturnValue OnBeforeResourceLoad( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, CefRefPtr<CefRequestCallback> callback) OVERRIDE;
在.cpp中重写函数
bool CCefBrowserEventHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, bool user_gesture, bool is_redirect) { CEF_REQUIRE_UI_THREAD(); return false; } CefRequestHandler::ReturnValue CCefBrowserEventHandler::OnBeforeResourceLoad( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, CefRefPtr<CefRequestCallback> callback) { wstring g_tokenValue; CefRequest::HeaderMap headers; headers.insert(std::make_pair(L"Authorization",g_tokenValue.c_str())); request->SetHeaderMap(headers); return RV_CONTINUE; }