Making a HTTP GET request with HTTP-Basic authentication

后端 未结 4 1000
旧时难觅i
旧时难觅i 2020-12-01 08:01

I need to build a proxy for a Flash Player project I\'m working on. I simply need to make a HTTP GET request with HTTP-Basic authentication to another URL, and serve the res

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 08:34

    Marc B did a great job of answering this question. I recently took his approach and wanted to share the resulting code.

    array(
        'method'=>"GET",
        'header' => "Authorization: Basic " . base64_encode("$username:$password")                 
      )
    );
    
    $context = stream_context_create($opts);
    
    // Open the file using the HTTP headers set above
    $file = file_get_contents($remote_url, false, $context);
    
    print($file);
    
    ?>
    

    I hope that this is helpful to people!

提交回复
热议问题