I'm doing some work with PyQt4 and QtWebKit, and in the web page request need to send a custom "Host" header along with the standard HTTP request. I'm not seeing any options for adding custom headers to the request, but this is all new to me so I hope I'm missing something. I'm looking here:
http://doc.qt.digia.com/4.6/qwebsettings.html
开发者_StackOverflow中文版Any advice would be greatly appreciated.
You can set headers on the QNetworkRequest that is sent:
QNetworkRequest request;
request.setUrl(QUrl("http://qt.nokia.com"));
request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
To use that custom request when loading a page, use the overloaded load function:
myWebView->load(request);
If you want to apply this to all requests QtWebKit makes, you can subclass QNetworkAccessManager
and reimplement its createRequest()
function to modify headers accordingly.
精彩评论