Qt는 5.6 QWebEngineUrlRequestInterceptor 무엇 당신이 QWebEngineView
달성하려고에 대한 제안 된 솔루션 가입일 :
QWebEngineUrlRequestInterceptor 인터페이스를 구현하고 차단 가능 프로파일에 인터셉터를 설치, 차단, 그들은 전에 URL 요청을 수정 Chromium의 네트워킹 스택에 도달합니다.
그것은 당신이 당신이 원하는 것을 얻을 수를 서브 클래 싱 할 필요가 의미하는 추상 클래스 :
#include <QWebEngineUrlRequestInterceptor>
#include <QDebug>
class RequestInterceptor : public QWebEngineUrlRequestInterceptor
{
public:
explicit RequestInterceptor(QObject * parent = Q_NULLPTR) : QWebEngineUrlRequestInterceptor(parent) {}
virtual void interceptRequest(QWebEngineUrlRequestInfo & info) Q_DECL_OVERRIDE;
};
void RequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo & info)
{
// Intercepting the requested URL
QUrl url = info.requestUrl();
qDebug() << "Request URL: " << url;
// Optionally redirect the request URL but it only works for requests
// without payload data such as GET ones
info.redirect(QUrl("https://www.google.com"));
// Set HTTP header
QByteArray httpHeaderName = "SomeHeaderName";
QByteArray httpHeaderValue = "SomeHeaderValue";
info.setHttpHeader(httpHeaderName, httpHeaderValue);
}
그런 다음이 같은 특정 QWebEnginePage
에 대한 QWebEngineProfile
이 인터셉터에 대한 포인터를 등록해야 :
QWebEngineView * view = new QWebEngineView;
RequestInterceptor * interceptor = new RequestInterceptor(view);
QWebEngineProfile * profile = new QWebEngineProfile(view);
profile->setRequestInterceptor(interceptor);
QWebEnginePage * page = new QWebEnginePage(profile, view);
view->setPage(page);