Http request with QNetworkRequest placing resolved ip address in HTTP host header not domain

  • I'm using wkhtmltopdf which is built on QT. When trying to run through a proxy that only allows whitelisted domains, I noticed that the http host header is being set with the resolved ip address versus the host name like a browser would set. Any ideas why this might be happening?

    The request is made with

    	typedef QPair<QString, QString> SSP;
     	foreach (const SSP & pair, settings.cookies)
    		multiPageLoader.cookieJar->useCookie(url, pair.first, pair.second);
    	QNetworkRequest r = QNetworkRequest(url);
    	typedef QPair<QString, QString> HT;
    	foreach (const HT & j, settings.customHeaders)
    		r.setRawHeader(j.first.toLatin1(), j.second.toLatin1());
    	if (postData.isEmpty())
    	else {
    		if (hasFiles)
    			r.setHeader(QNetworkRequest::ContentTypeHeader, QString("multipart/form-data, boundary=")+boundary);
    		webPage.mainFrame()->load(r, QNetworkAccessManager::PostOperation, postData);

  • Moderators

    what is the value of the url variable?

  • @raven-worx It it a Qurl. I added a printf to ensure it is holding the url using the domain name and it is. For example in my test

    Running it through charles proxy shows the IP being specified in the host header param
    0_1519665403444_Screen Shot 2018-02-23 at 7.13.26 PM.png

    To compare this is a browser hitting the url
    0_1519665394972_Screen Shot 2018-02-23 at 7.12.47 PM.png

  • Qt Champions 2018

    What version of Qt are you using?

  • Version 4.8

  • Qt Champions 2018

    7 years old and unsupported so might be a minor bug that was since resolved (I haven't tested Qt 5.10)

  • @VRonin It might be related to QNetworkProxy::HostNameLookupCapability. I'm looking into it

  • Qt Champions 2018

    If you provide a minimal example (using a public proxy) I can test if the current version is still affected

  • The issue was resolved by specifying QNetworkProxy::HostNameLookupCapability. I'm not sure if that is the desired effect to have no trace of the host at/past the proxy when it is not specified. It seems like that would cause issues when multiple domains share an ip.

  • It is also only for https (http sends the hostname either way)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.