views:

19

answers:

1

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.trolltech.com/4.6/qwebsettings.html

Any advice would be greatly appreciated.

+1  A: 

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);
Kaleb Pederson
Does this override all of the default headers, or does this just add and replace existing headers?
lennysan
Any idea why it would hang when I use a "Host: mysite.com" but works fine when i use "Host: www.mysite.com"? I would expect the webserver to respond in either case, but in the first case the call just sits there indefinitely.
lennysan
That behavior depends on the web server being used. When a server supports multiple (virtual) hosts, it must use the `host` header to determine to which virtual host the request should be sent.
Kaleb Pederson

related questions