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 24 Feb 2018, 00:35 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);
    	}
    
    R 1 Reply Last reply 25 Feb 2018, 21:41
    0
    • J jasonparallel
      24 Feb 2018, 00:35

      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);
      	}
      
      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 25 Feb 2018, 21:41 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 26 Feb 2018, 17:18
      0
      • R raven-worx
        25 Feb 2018, 21:41

        @jasonparallel
        what is the value of the url variable?

        J Offline
        J Offline
        jasonparallel
        wrote on 26 Feb 2018, 17:18 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
        • V Offline
          V Offline
          VRonin
          wrote on 26 Feb 2018, 17:47 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 26 Feb 2018, 17:58 last edited by
            #5

            Version 4.8

            1 Reply Last reply
            0
            • V Offline
              V Offline
              VRonin
              wrote on 26 Feb 2018, 18:55 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 26 Feb 2018, 20:30
              0
              • V VRonin
                26 Feb 2018, 18:55

                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 26 Feb 2018, 20:30 last edited by
                #7

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

                V 1 Reply Last reply 26 Feb 2018, 20:32
                0
                • J jasonparallel
                  26 Feb 2018, 20:30

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

                  V Offline
                  V Offline
                  VRonin
                  wrote on 26 Feb 2018, 20:32 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 27 Feb 2018, 03:01 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 27 Feb 2018, 16:13
                    0
                    • J jasonparallel
                      27 Feb 2018, 03:01

                      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 27 Feb 2018, 16:13 last edited by
                      #10

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

                      1 Reply Last reply
                      0

                      10/10

                      27 Feb 2018, 16:13

                      • Login

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