Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Using a proxy for certain URL calls made by app
Forum Updated to NodeBB v4.3 + New Features

Using a proxy for certain URL calls made by app

Scheduled Pinned Locked Moved Unsolved C++ Gurus
15 Posts 5 Posters 3.5k Views 3 Watching
  • 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
    JrDeskJockey
    wrote on 21 Jun 2018, 21:19 last edited by
    #1

    Hello, I am fairly new to Qt. I am writing an app in QML but need to set a proxy in main.cpp. I have successfully defined an app-wide proxy with a simple line like...
    QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy, "one.proxy.myserver.com", 8888));

    The issue is that my company requires me to not hit one.proxy.myserver.com when the http request is on our internal network. I have been Googling and reviewing Qt documentation but I'm still baffled. I see there is QNetworkProxyFactory, QNetworkProxyQuery, etc, but I can't seem to figure out how to pull it together. What I'd like to do is say, app wide......

    1. all requests for "myinternalserver.mycompany.com" do not use a proxy at all
    2. all other requests hit one.proxy.myserver.com

    Is that possible? Does anyone have a small bit of sample code to do that?

    Thanks so much for your help.

    P 1 Reply Last reply 22 Jun 2018, 16:54
    0
    • J JrDeskJockey
      21 Jun 2018, 21:19

      Hello, I am fairly new to Qt. I am writing an app in QML but need to set a proxy in main.cpp. I have successfully defined an app-wide proxy with a simple line like...
      QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy, "one.proxy.myserver.com", 8888));

      The issue is that my company requires me to not hit one.proxy.myserver.com when the http request is on our internal network. I have been Googling and reviewing Qt documentation but I'm still baffled. I see there is QNetworkProxyFactory, QNetworkProxyQuery, etc, but I can't seem to figure out how to pull it together. What I'd like to do is say, app wide......

      1. all requests for "myinternalserver.mycompany.com" do not use a proxy at all
      2. all other requests hit one.proxy.myserver.com

      Is that possible? Does anyone have a small bit of sample code to do that?

      Thanks so much for your help.

      P Offline
      P Offline
      Pablo J. Rogina
      wrote on 22 Jun 2018, 16:54 last edited by
      #2

      @JrDeskJockey said in Using a proxy for certain URL calls made by app:

      QNetworkProxyFactory

      Not that I'm used that class that much, but it seems to be what you're looking for, in particular method proxyForQuery()

      Maybe this test example can also guide you understanding what you need to do.

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      A 1 Reply Last reply 30 Jul 2018, 16:18
      3
      • J Offline
        J Offline
        JrDeskJockey
        wrote on 27 Jun 2018, 20:50 last edited by
        #3

        So....I don't get it. I wonder, how do you setup the proxy factory? I see the proxy query, you can define a URL and pass that to the factory, but how do you establish the factory in the first place so that it knows of your specific domains you want to track and either exclude or include for a proxy?

        J 1 Reply Last reply 28 Jun 2018, 05:15
        0
        • J JrDeskJockey
          27 Jun 2018, 20:50

          So....I don't get it. I wonder, how do you setup the proxy factory? I see the proxy query, you can define a URL and pass that to the factory, but how do you establish the factory in the first place so that it knows of your specific domains you want to track and either exclude or include for a proxy?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 28 Jun 2018, 05:15 last edited by
          #4

          @JrDeskJockey http://doc.qt.io/qt-5/qnetworkproxyfactory.html#setApplicationProxyFactory

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          4
          • P Pablo J. Rogina
            22 Jun 2018, 16:54

            @JrDeskJockey said in Using a proxy for certain URL calls made by app:

            QNetworkProxyFactory

            Not that I'm used that class that much, but it seems to be what you're looking for, in particular method proxyForQuery()

            Maybe this test example can also guide you understanding what you need to do.

            A Offline
            A Offline
            AtoZ
            wrote on 30 Jul 2018, 16:18 last edited by
            #5

            @Pablo-J.-Rogina When I downloaded qt-master/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro, and tried to look at it in Qt Creator, I got an error: Cannot find feature qttest_p4. What am I missing? What is qttest_p4 for? Thanks!

            J 1 Reply Last reply 31 Jul 2018, 04:49
            0
            • A AtoZ
              30 Jul 2018, 16:18

              @Pablo-J.-Rogina When I downloaded qt-master/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro, and tried to look at it in Qt Creator, I got an error: Cannot find feature qttest_p4. What am I missing? What is qttest_p4 for? Thanks!

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 31 Jul 2018, 04:49 last edited by
              #6

              @AtoZ Try to comment out

              load(qttest_p4)
              

              in pro file.
              Maybe you need to add

              CONFIG+=testcase
              

              to the pro file instead.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply 31 Jul 2018, 15:17
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 31 Jul 2018, 06:36 last edited by
                #7

                Hi,

                @AtoZ said in Using a proxy for certain URL calls made by app:

                qt-master

                Where does that come from ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                A 1 Reply Last reply 31 Jul 2018, 14:57
                0
                • S SGaist
                  31 Jul 2018, 06:36

                  Hi,

                  @AtoZ said in Using a proxy for certain URL calls made by app:

                  qt-master

                  Where does that come from ?

                  A Offline
                  A Offline
                  AtoZ
                  wrote on 31 Jul 2018, 14:57 last edited by
                  #8

                  @SGaist qt-master comes from the test example that Pablo referred to in his post.

                  1 Reply Last reply
                  0
                  • J jsulm
                    31 Jul 2018, 04:49

                    @AtoZ Try to comment out

                    load(qttest_p4)
                    

                    in pro file.
                    Maybe you need to add

                    CONFIG+=testcase
                    

                    to the pro file instead.

                    A Offline
                    A Offline
                    AtoZ
                    wrote on 31 Jul 2018, 15:17 last edited by
                    #9

                    @jsulm Thanks for your reply. After I comment out load(qttest_p4) and build again, I get unsolved externals issue. Adding CONFIG+=testcase does not solve the issue. I still miss some pieces. Can you please help again? 0_1533050237843_unresolved_external_qt.JPG

                    P J 2 Replies Last reply 31 Jul 2018, 15:22
                    0
                    • A AtoZ
                      31 Jul 2018, 15:17

                      @jsulm Thanks for your reply. After I comment out load(qttest_p4) and build again, I get unsolved externals issue. Adding CONFIG+=testcase does not solve the issue. I still miss some pieces. Can you please help again? 0_1533050237843_unresolved_external_qt.JPG

                      P Offline
                      P Offline
                      Pablo J. Rogina
                      wrote on 31 Jul 2018, 15:22 last edited by
                      #10

                      @AtoZ my suggestion was to look at the test code and figure out how the QNetworkProxyFactory is being used, not to run the test itself. I'm not sure but you may need to start one or two levels up for actually running the test(s)

                      Upvote the answer(s) that helped you solve the issue
                      Use "Topic Tools" button to mark your post as Solved
                      Add screenshots via postimage.org
                      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                      A 1 Reply Last reply 31 Jul 2018, 18:41
                      0
                      • P Pablo J. Rogina
                        31 Jul 2018, 15:22

                        @AtoZ my suggestion was to look at the test code and figure out how the QNetworkProxyFactory is being used, not to run the test itself. I'm not sure but you may need to start one or two levels up for actually running the test(s)

                        A Offline
                        A Offline
                        AtoZ
                        wrote on 31 Jul 2018, 18:41 last edited by
                        #11

                        @Pablo-J.-Rogina Thanks for your tips and quick reply, Pablo. I'd like to see how test is done because it is hard to track network traffic, isn't it? The code you referred does give a good example on how to test a running networkproxyfactory, even if it does not build successfully because of missing libraries, I think.

                        1 Reply Last reply
                        0
                        • A AtoZ
                          31 Jul 2018, 15:17

                          @jsulm Thanks for your reply. After I comment out load(qttest_p4) and build again, I get unsolved externals issue. Adding CONFIG+=testcase does not solve the issue. I still miss some pieces. Can you please help again? 0_1533050237843_unresolved_external_qt.JPG

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 1 Aug 2018, 04:45 last edited by
                          #12

                          @AtoZ Try

                          QT += testlib
                          

                          http://doc.qt.io/qt-5/qtest.html

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          A 1 Reply Last reply 1 Aug 2018, 14:10
                          1
                          • J jsulm
                            1 Aug 2018, 04:45

                            @AtoZ Try

                            QT += testlib
                            

                            http://doc.qt.io/qt-5/qtest.html

                            A Offline
                            A Offline
                            AtoZ
                            wrote on 1 Aug 2018, 14:10 last edited by
                            #13

                            @jsulm @Pablo-J-Rogina Yes, you are right. I think QT += network testlib needs to be added in the .pro file. Since I realized there may be some missing pieces, I created a new unit test project in Qt Creator and migrated the tst_qnetworkproxyfactory code over, and then I was able to run it through Q Creator. Thanks for all your help. My next endeavor will be actually using qnetworkproxyfactory to direct networkflow to use proxy server for external http/s calls and not to use it for internal http/s calls. The project I am working on is a Q Quick project, which mostly built upon qml and javascript, so I am wondering where I should add the networkproxyfactory piece. Shall I create a subclass of qnetworkproxyfactory and use it in main.cpp (this is the way I am trying) or actually I have to modify and recompile network module (which I am trying to avoid) - because I am unsure of how to use qnetworkproxyfactory to track the http/https calls which are actually set in qml. Do you have any suggestions? Thanks again.

                            P 1 Reply Last reply 1 Aug 2018, 14:34
                            0
                            • A AtoZ
                              1 Aug 2018, 14:10

                              @jsulm @Pablo-J-Rogina Yes, you are right. I think QT += network testlib needs to be added in the .pro file. Since I realized there may be some missing pieces, I created a new unit test project in Qt Creator and migrated the tst_qnetworkproxyfactory code over, and then I was able to run it through Q Creator. Thanks for all your help. My next endeavor will be actually using qnetworkproxyfactory to direct networkflow to use proxy server for external http/s calls and not to use it for internal http/s calls. The project I am working on is a Q Quick project, which mostly built upon qml and javascript, so I am wondering where I should add the networkproxyfactory piece. Shall I create a subclass of qnetworkproxyfactory and use it in main.cpp (this is the way I am trying) or actually I have to modify and recompile network module (which I am trying to avoid) - because I am unsure of how to use qnetworkproxyfactory to track the http/https calls which are actually set in qml. Do you have any suggestions? Thanks again.

                              P Offline
                              P Offline
                              Pablo J. Rogina
                              wrote on 1 Aug 2018, 14:34 last edited by
                              #14

                              @AtoZ said in Using a proxy for certain URL calls made by app:

                              migrated the tst_qnetworkproxyfactory code over, and then I was able to run it through Q Creator

                              Glad you have advanced so far.

                              how to use qnetworkproxyfactory to track the http/https calls which are actually set in qml

                              May I suggest you open another post on its own since that question is slightly more specific (QML + proxies)?

                              Upvote the answer(s) that helped you solve the issue
                              Use "Topic Tools" button to mark your post as Solved
                              Add screenshots via postimage.org
                              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                              A 1 Reply Last reply 1 Aug 2018, 15:53
                              0
                              • P Pablo J. Rogina
                                1 Aug 2018, 14:34

                                @AtoZ said in Using a proxy for certain URL calls made by app:

                                migrated the tst_qnetworkproxyfactory code over, and then I was able to run it through Q Creator

                                Glad you have advanced so far.

                                how to use qnetworkproxyfactory to track the http/https calls which are actually set in qml

                                May I suggest you open another post on its own since that question is slightly more specific (QML + proxies)?

                                A Offline
                                A Offline
                                AtoZ
                                wrote on 1 Aug 2018, 15:53 last edited by
                                #15

                                @Pablo-J.-Rogina Sure will do.

                                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