Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Http request with QNetworkRequest placing resolved ip address in HTTP host header not domain

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jasonparallel
    wrote on last edited by
    #1

    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

    //multiPageLoader.cookieJar->clearExtraCookies();
    	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())
    		webPage.mainFrame()->load(r);
    	else {
    		if (hasFiles)
    			r.setHeader(QNetworkRequest::ContentTypeHeader, QString("multipart/form-data, boundary=")+boundary);
    		webPage.mainFrame()->load(r, QNetworkAccessManager::PostOperation, postData);
    	}
    
    raven-worxR 1 Reply Last reply
    0
    • J jasonparallel

      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

      //multiPageLoader.cookieJar->clearExtraCookies();
      	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())
      		webPage.mainFrame()->load(r);
      	else {
      		if (hasFiles)
      			r.setHeader(QNetworkRequest::ContentTypeHeader, QString("multipart/form-data, boundary=")+boundary);
      		webPage.mainFrame()->load(r, QNetworkAccessManager::PostOperation, postData);
      	}
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @jasonparallel
      what is the value of the url variable?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      J 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @jasonparallel
        what is the value of the url variable?

        J Offline
        J Offline
        jasonparallel
        wrote on last edited by jasonparallel
        #3

        @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 https://thehackernews.com

        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

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          What version of Qt are you using?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jasonparallel
            wrote on last edited by
            #5

            Version 4.8

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

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

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              J 1 Reply Last reply
              0
              • VRoninV VRonin

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

                J Offline
                J Offline
                jasonparallel
                wrote on last edited by
                #7

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

                VRoninV 1 Reply Last reply
                0
                • J jasonparallel

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

                  VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

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

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jasonparallel
                    wrote on last edited by
                    #9

                    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.

                    J 1 Reply Last reply
                    0
                    • J jasonparallel

                      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.

                      J Offline
                      J Offline
                      jasonparallel
                      wrote on last edited by
                      #10

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

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved