<small id='hEi2q'></small><noframes id='hEi2q'>

<legend id='hEi2q'><style id='hEi2q'><dir id='hEi2q'><q id='hEi2q'></q></dir></style></legend>

    <i id='hEi2q'><tr id='hEi2q'><dt id='hEi2q'><q id='hEi2q'><span id='hEi2q'><b id='hEi2q'><form id='hEi2q'><ins id='hEi2q'></ins><ul id='hEi2q'></ul><sub id='hEi2q'></sub></form><legend id='hEi2q'></legend><bdo id='hEi2q'><pre id='hEi2q'><center id='hEi2q'></center></pre></bdo></b><th id='hEi2q'></th></span></q></dt></tr></i><div id='hEi2q'><tfoot id='hEi2q'></tfoot><dl id='hEi2q'><fieldset id='hEi2q'></fieldset></dl></div>

    • <bdo id='hEi2q'></bdo><ul id='hEi2q'></ul>
      <tfoot id='hEi2q'></tfoot>

        cURL 需要代理身份验证

        时间:2023-07-16

          <legend id='tceeq'><style id='tceeq'><dir id='tceeq'><q id='tceeq'></q></dir></style></legend>

          <small id='tceeq'></small><noframes id='tceeq'>

          1. <tfoot id='tceeq'></tfoot>
              <i id='tceeq'><tr id='tceeq'><dt id='tceeq'><q id='tceeq'><span id='tceeq'><b id='tceeq'><form id='tceeq'><ins id='tceeq'></ins><ul id='tceeq'></ul><sub id='tceeq'></sub></form><legend id='tceeq'></legend><bdo id='tceeq'><pre id='tceeq'><center id='tceeq'></center></pre></bdo></b><th id='tceeq'></th></span></q></dt></tr></i><div id='tceeq'><tfoot id='tceeq'></tfoot><dl id='tceeq'><fieldset id='tceeq'></fieldset></dl></div>
                  <tbody id='tceeq'></tbody>
                • <bdo id='tceeq'></bdo><ul id='tceeq'></ul>
                  本文介绍了cURL 需要代理身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想使用 cURL 函数,但我在代理后面,所以我收到 HTTP/1.1 407 Proxy Authentication Required 错误...

                  I would like to use a cURL function, but I'm behind a proxy, so I get an HTTP/1.1 407 Proxy Authentication Required error...

                  这是我使用的php代码:

                  This is the php code I use:

                  $proxy_user = 'Michiel';
                  $proxy_pass = 'mypassword';
                  $proxy_url = 'myproxyurl:port';
                  $proxy = true;
                  
                  $service_url = "https://www.myapiurltocall.com";
                  $service_user = 'user:password:FO';
                  $service_pass = 'password';
                  
                  $ch = curl_init($service_url);
                  
                  // Set proxy if necessary
                  if ($proxy) {
                      curl_setopt($ch, CURLOPT_PROXY, $proxy_url);
                      curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_user.':'.$proxy_pass);
                      curl_setopt($ch, CURLOPT_PROXYPORT, 8080);
                      curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
                  }
                  
                  // Set service authentication
                  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
                  curl_setopt($ch, CURLOPT_USERPWD, "{$service_user}:{$service_pass}");
                  
                  // HTTP headers
                  $headers['Authorization'] = 'Basic ' . base64_encode("$proxy_user:$proxy_pass");
                  
                  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);    
                  curl_setopt($ch, CURLOPT_VERBOSE, 1);
                  curl_setopt($ch, CURLOPT_HEADER, TRUE);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                  curl_setopt($ch, CURLOPT_ENCODING, '');
                  curl_setopt($ch, CURLOPT_TIMEOUT, 15);
                  
                  //WARNING: this would prevent curl from detecting a 'man in the middle' attack
                  curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
                  curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
                  
                  $data = curl_exec($ch);
                  

                  而且我不知道我做错了什么......我该如何解决这个错误?

                  And I don't know what I do wrong... How can I get around this error?

                  推荐答案

                  这是我最常用的:

                  function curlFile($url,$proxy_ip,$proxy_port,$loginpassw)
                  {
                      //$loginpassw = 'username:password';
                      //$proxy_ip = '192.168.1.1';
                      //$proxy_port = '12345';
                      //$url = 'http://www.domain.com';
                  
                      $ch = curl_init();
                      curl_setopt($ch, CURLOPT_URL, $url);
                      curl_setopt($ch, CURLOPT_HEADER, 0);
                      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                      curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
                      curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
                      curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
                      curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw);
                      $data = curl_exec($ch);
                      curl_close($ch);
                  
                      return $data;
                  }
                  

                  这篇关于cURL 需要代理身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用带有 cURL 的 SOCKS 5 代理? 下一篇:没有了

                  相关文章

                    • <bdo id='AFtys'></bdo><ul id='AFtys'></ul>
                  1. <i id='AFtys'><tr id='AFtys'><dt id='AFtys'><q id='AFtys'><span id='AFtys'><b id='AFtys'><form id='AFtys'><ins id='AFtys'></ins><ul id='AFtys'></ul><sub id='AFtys'></sub></form><legend id='AFtys'></legend><bdo id='AFtys'><pre id='AFtys'><center id='AFtys'></center></pre></bdo></b><th id='AFtys'></th></span></q></dt></tr></i><div id='AFtys'><tfoot id='AFtys'></tfoot><dl id='AFtys'><fieldset id='AFtys'></fieldset></dl></div>

                      <small id='AFtys'></small><noframes id='AFtys'>

                      <legend id='AFtys'><style id='AFtys'><dir id='AFtys'><q id='AFtys'></q></dir></style></legend>
                      <tfoot id='AFtys'></tfoot>