I want to port my app from Qt WebKit to Qt WebEngine. In Qt Webkit I can set http headers by using QNetworkRequest, but in Qt WebEngine, the doc says:
Qt WebEngine has its own HTTP implementation and cannot go through a QNetworkAccessManager
I use PyQt5 and Qt5.8.
I cannot find how to set http headers in Qt WebEngine.
--------------update----------------
Finally, it worked! Thanks! @Trilarion:
define my QWebEngineUrlRequestInterceptor class
class NWUrlRequestInterceptor(QWebEngineUrlRequestInterceptor):
def __init__(self, headers):
super(QWebEngineUrlRequestInterceptor, self).__init__()
self.headers = headers
def set_headers(self,headers):
self.headers = headers
def interceptRequest(self, info):
print info, self.headers
for header, value in self.headers:
info.setHttpHeader(header, value);
use in my browser:
self.request_interceptor = NWUrlRequestInterceptor(self.headers)
self.webpage.profile().setRequestInterceptor(self.request_interceptor)