lennysan
lennysan

Reputation: 1350

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.

Upvotes: 7

Views: 3942

Answers (2)

Kaleb Pederson
Kaleb Pederson

Reputation: 46469

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

Upvotes: 11

kralyk
kralyk

Reputation: 4387

If you want to apply this to all requests QtWebKit makes, you can subclass QNetworkAccessManager and reimplement its createRequest() function to modify headers accordingly.

Upvotes: 3

Related Questions