开发者

Sending a custom header along with qtwebkit request

开发者 https://www.devze.com 2023-01-15 19:03 出处:网络
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 head

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消