Proxy Authentication Required with cURL

前端 未结 4 1580
梦如初夏
梦如初夏 2020-12-14 03:33

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...

This is the php code I use

4条回答
  •  余生分开走
    2020-12-14 04:22

    Try to implement this in your function

       function send_string($data) {
    //       pr($data);exit;
    
         $equi_input="Your values";
    //  echo $equi_input; exit;
            $agent = ""//Agent Setting for Netscape  
            $url = ""; // URL to POST FORM. (Action of Form)
            //xml format
             $efx_request=strtoupper($equi_input);
          //echo  $efx_request;exit;
            $post_fields = "site_id=""&service_name=""&efx_request=$efx_request";
            $credentials = ;
            $headers = array("HTTP/1.1",
                "Content-Type: application/x-www-form-urlencoded",
                "Authorization: Basic " . $credentials
            );
            $fh = fopen('/tmp/test.txt', 'w') or die("can't open file"); //File to write the header information of the curl request.
            $ch = curl_init();    // Initialize a CURL session.
            curl_setopt($ch, CURLOPT_USERAGENT, $agent);
            curl_setopt($ch, CURLOPT_URL, $url);  // Pass URL as parameter.
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($ch, CURLOPT_STDERR, $fh);
            curl_setopt($ch, CURLOPT_POST, 1); // use this option to Post a form  
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); // Pass form Fields.  
            curl_setopt($ch, CURLOPT_VERBOSE, '1');
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1');
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $result = curl_exec($ch);  // grab URL and pass it to the variable.
            curl_close($ch);  // close curl resource, and free system resources.  
            fclose($fh);
    
    
       //echo '
    ';print_r($array);echo '
    ';exit; if (!empty($result)) { return $result; } else { echo "Curl Error" . curl_error($ch); } }

    check request send 200ok ...

    And check your secure certificate if you are using....

    Thanks.

提交回复
热议问题