Created
October 22, 2009 18:01
-
-
Save brettg/216139 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# Posterous.com API HTTP AUTH Example | |
require 'base64' | |
require 'open-uri' | |
require 'net/http' | |
user = '[email protected]' | |
password = 'password' | |
host = 'posterous.com' | |
path = '/api/newpost' | |
# build the header ourselves | |
auth_header = "Basic #{Base64.encode64("#{user}:#{password}")}" | |
open("http://#{host}#{path}", 'Authorization' => auth_header) do |r| | |
puts r.read | |
end | |
# use ruby standard library in HTTP AUTH | |
Net::HTTP.start(host) do |http| | |
req = Net::HTTP::Get.new(path) | |
req.basic_auth user, password | |
response = http.request(req) | |
puts response.body | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment