Search code examples
webkitpyqtpyqt4qtwebkit

Sending a custom header along with qtwebkit request


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

Any advice would be greatly appreciated.


Solution

  • 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);