Created
August 14, 2014 19:40
-
-
Save gabrysiak/ff94b0732332192d271d to your computer and use it in GitHub Desktop.
PHP - HTTP Request with Basic Authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$username = "some-username"; | |
$password = "some-password"; | |
$remote_url = 'http://www.somedomain.com/path/to/file'; | |
// Create a stream | |
$opts = array( | |
'http'=>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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
getting " failed to open stream: HTTP request failed! HTTP/1.0 411 Length Required"