I need this in Ruby:
$context = stream_context_create(array(
'http' => array(
'header' => "Authoriz开发者_如何学Pythonation: Basic " . base64_encode("user:pass")
)
));
$output = file_get_contents("http://example.com/file.php", false, $context);
Thanks.
Check out Net::HTTP.
require 'net/http'
output = nil
Net::HTTP.start('example.com') {|http|
req = Net::HTTP::Get.new('/file.php')
req.basic_auth 'user', 'pass'
response = http.request(req)
output = response.body
}
精彩评论