Proxy settings for HTTP request using libcurl












0















I am fairly new to HTTP Protocols involving proxies and authentication. I am working on an application that runs on Windows and uses the host network to send/receive HTTP/S requests. It also uses Libcurl to help the transfer.



However, I have a few issues when I have to use a proxy. Since I am on a network, I have a proxy defined for certain URLs with a PAC file. Since Libcurl does not have Javascript support, I use PACParser to parse the PAC file and determine the proxy.



When I use the proxy I get 407 authentication required. I am not sure how to overcome proxy authentication. I tried various available settings with CURL like BASIC / DIGEST / NTLM. None of them seems to work. But if I hardcode the username and password in the request I see the request go through.



How can I avoid hardcoding the username/password and stil ensure that proxy usage will work?










share|improve this question





























    0















    I am fairly new to HTTP Protocols involving proxies and authentication. I am working on an application that runs on Windows and uses the host network to send/receive HTTP/S requests. It also uses Libcurl to help the transfer.



    However, I have a few issues when I have to use a proxy. Since I am on a network, I have a proxy defined for certain URLs with a PAC file. Since Libcurl does not have Javascript support, I use PACParser to parse the PAC file and determine the proxy.



    When I use the proxy I get 407 authentication required. I am not sure how to overcome proxy authentication. I tried various available settings with CURL like BASIC / DIGEST / NTLM. None of them seems to work. But if I hardcode the username and password in the request I see the request go through.



    How can I avoid hardcoding the username/password and stil ensure that proxy usage will work?










    share|improve this question



























      0












      0








      0








      I am fairly new to HTTP Protocols involving proxies and authentication. I am working on an application that runs on Windows and uses the host network to send/receive HTTP/S requests. It also uses Libcurl to help the transfer.



      However, I have a few issues when I have to use a proxy. Since I am on a network, I have a proxy defined for certain URLs with a PAC file. Since Libcurl does not have Javascript support, I use PACParser to parse the PAC file and determine the proxy.



      When I use the proxy I get 407 authentication required. I am not sure how to overcome proxy authentication. I tried various available settings with CURL like BASIC / DIGEST / NTLM. None of them seems to work. But if I hardcode the username and password in the request I see the request go through.



      How can I avoid hardcoding the username/password and stil ensure that proxy usage will work?










      share|improve this question
















      I am fairly new to HTTP Protocols involving proxies and authentication. I am working on an application that runs on Windows and uses the host network to send/receive HTTP/S requests. It also uses Libcurl to help the transfer.



      However, I have a few issues when I have to use a proxy. Since I am on a network, I have a proxy defined for certain URLs with a PAC file. Since Libcurl does not have Javascript support, I use PACParser to parse the PAC file and determine the proxy.



      When I use the proxy I get 407 authentication required. I am not sure how to overcome proxy authentication. I tried various available settings with CURL like BASIC / DIGEST / NTLM. None of them seems to work. But if I hardcode the username and password in the request I see the request go through.



      How can I avoid hardcoding the username/password and stil ensure that proxy usage will work?







      windows proxy http win32






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 16 '13 at 12:43









      Jonathan Garber

      623518




      623518










      asked May 16 '13 at 12:09









      linux developerlinux developer

      10114




      10114






















          1 Answer
          1






          active

          oldest

          votes


















          0














          See libcurl-tutorial (3), section Environment Variables:



          libcurl automatically checks and uses a set of environment
          variables to know what proxies to use for certain
          protocols. The names of the variables are following an
          ancient de facto standard and are built up
          as "[protocol]_proxy" (note the lower casing). Which makes
          the variable 'http_proxy' checked for a name of a proxy to
          use when the input URL is HTTP. Following the same rule, the
          variable named 'ftp_proxy' is checked for FTP URLs. Again,
          the proxies are always HTTP proxies, the different names of
          the variables simply allows different HTTP proxies to be
          used.

          The proxy environment variable contents should be in the
          format "[protocol://][user:password@]machine[:port]".


          So you have to enter the proxy in the environment variable settings, not the network settings.






          share|improve this answer
























          • But i am trying to understand a way to achieve proxy authentication if my proxy mandates one.

            – linux developer
            May 16 '13 at 16:21











          • adding user:password@ does not work?

            – artistoex
            May 17 '13 at 8:29











          • i was assuming Curl can negotiate with the host machine to retrieve the user name and password during transfer. It is something we need to derive the username and password? <b> I tried to explore winhttp "http query option" to get the username and pwd. Is this something a right direction Or there are someother mechanism to fetch the proxy username and password

            – linux developer
            May 17 '13 at 16:57













          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f596276%2fproxy-settings-for-http-request-using-libcurl%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          See libcurl-tutorial (3), section Environment Variables:



          libcurl automatically checks and uses a set of environment
          variables to know what proxies to use for certain
          protocols. The names of the variables are following an
          ancient de facto standard and are built up
          as "[protocol]_proxy" (note the lower casing). Which makes
          the variable 'http_proxy' checked for a name of a proxy to
          use when the input URL is HTTP. Following the same rule, the
          variable named 'ftp_proxy' is checked for FTP URLs. Again,
          the proxies are always HTTP proxies, the different names of
          the variables simply allows different HTTP proxies to be
          used.

          The proxy environment variable contents should be in the
          format "[protocol://][user:password@]machine[:port]".


          So you have to enter the proxy in the environment variable settings, not the network settings.






          share|improve this answer
























          • But i am trying to understand a way to achieve proxy authentication if my proxy mandates one.

            – linux developer
            May 16 '13 at 16:21











          • adding user:password@ does not work?

            – artistoex
            May 17 '13 at 8:29











          • i was assuming Curl can negotiate with the host machine to retrieve the user name and password during transfer. It is something we need to derive the username and password? <b> I tried to explore winhttp "http query option" to get the username and pwd. Is this something a right direction Or there are someother mechanism to fetch the proxy username and password

            – linux developer
            May 17 '13 at 16:57


















          0














          See libcurl-tutorial (3), section Environment Variables:



          libcurl automatically checks and uses a set of environment
          variables to know what proxies to use for certain
          protocols. The names of the variables are following an
          ancient de facto standard and are built up
          as "[protocol]_proxy" (note the lower casing). Which makes
          the variable 'http_proxy' checked for a name of a proxy to
          use when the input URL is HTTP. Following the same rule, the
          variable named 'ftp_proxy' is checked for FTP URLs. Again,
          the proxies are always HTTP proxies, the different names of
          the variables simply allows different HTTP proxies to be
          used.

          The proxy environment variable contents should be in the
          format "[protocol://][user:password@]machine[:port]".


          So you have to enter the proxy in the environment variable settings, not the network settings.






          share|improve this answer
























          • But i am trying to understand a way to achieve proxy authentication if my proxy mandates one.

            – linux developer
            May 16 '13 at 16:21











          • adding user:password@ does not work?

            – artistoex
            May 17 '13 at 8:29











          • i was assuming Curl can negotiate with the host machine to retrieve the user name and password during transfer. It is something we need to derive the username and password? <b> I tried to explore winhttp "http query option" to get the username and pwd. Is this something a right direction Or there are someother mechanism to fetch the proxy username and password

            – linux developer
            May 17 '13 at 16:57
















          0












          0








          0







          See libcurl-tutorial (3), section Environment Variables:



          libcurl automatically checks and uses a set of environment
          variables to know what proxies to use for certain
          protocols. The names of the variables are following an
          ancient de facto standard and are built up
          as "[protocol]_proxy" (note the lower casing). Which makes
          the variable 'http_proxy' checked for a name of a proxy to
          use when the input URL is HTTP. Following the same rule, the
          variable named 'ftp_proxy' is checked for FTP URLs. Again,
          the proxies are always HTTP proxies, the different names of
          the variables simply allows different HTTP proxies to be
          used.

          The proxy environment variable contents should be in the
          format "[protocol://][user:password@]machine[:port]".


          So you have to enter the proxy in the environment variable settings, not the network settings.






          share|improve this answer













          See libcurl-tutorial (3), section Environment Variables:



          libcurl automatically checks and uses a set of environment
          variables to know what proxies to use for certain
          protocols. The names of the variables are following an
          ancient de facto standard and are built up
          as "[protocol]_proxy" (note the lower casing). Which makes
          the variable 'http_proxy' checked for a name of a proxy to
          use when the input URL is HTTP. Following the same rule, the
          variable named 'ftp_proxy' is checked for FTP URLs. Again,
          the proxies are always HTTP proxies, the different names of
          the variables simply allows different HTTP proxies to be
          used.

          The proxy environment variable contents should be in the
          format "[protocol://][user:password@]machine[:port]".


          So you have to enter the proxy in the environment variable settings, not the network settings.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 16 '13 at 12:30









          artistoexartistoex

          3,01311634




          3,01311634













          • But i am trying to understand a way to achieve proxy authentication if my proxy mandates one.

            – linux developer
            May 16 '13 at 16:21











          • adding user:password@ does not work?

            – artistoex
            May 17 '13 at 8:29











          • i was assuming Curl can negotiate with the host machine to retrieve the user name and password during transfer. It is something we need to derive the username and password? <b> I tried to explore winhttp "http query option" to get the username and pwd. Is this something a right direction Or there are someother mechanism to fetch the proxy username and password

            – linux developer
            May 17 '13 at 16:57





















          • But i am trying to understand a way to achieve proxy authentication if my proxy mandates one.

            – linux developer
            May 16 '13 at 16:21











          • adding user:password@ does not work?

            – artistoex
            May 17 '13 at 8:29











          • i was assuming Curl can negotiate with the host machine to retrieve the user name and password during transfer. It is something we need to derive the username and password? <b> I tried to explore winhttp "http query option" to get the username and pwd. Is this something a right direction Or there are someother mechanism to fetch the proxy username and password

            – linux developer
            May 17 '13 at 16:57



















          But i am trying to understand a way to achieve proxy authentication if my proxy mandates one.

          – linux developer
          May 16 '13 at 16:21





          But i am trying to understand a way to achieve proxy authentication if my proxy mandates one.

          – linux developer
          May 16 '13 at 16:21













          adding user:password@ does not work?

          – artistoex
          May 17 '13 at 8:29





          adding user:password@ does not work?

          – artistoex
          May 17 '13 at 8:29













          i was assuming Curl can negotiate with the host machine to retrieve the user name and password during transfer. It is something we need to derive the username and password? <b> I tried to explore winhttp "http query option" to get the username and pwd. Is this something a right direction Or there are someother mechanism to fetch the proxy username and password

          – linux developer
          May 17 '13 at 16:57







          i was assuming Curl can negotiate with the host machine to retrieve the user name and password during transfer. It is something we need to derive the username and password? <b> I tried to explore winhttp "http query option" to get the username and pwd. Is this something a right direction Or there are someother mechanism to fetch the proxy username and password

          – linux developer
          May 17 '13 at 16:57




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f596276%2fproxy-settings-for-http-request-using-libcurl%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар