Retrieving yahoo! mail?


As an exercise, I’m trying to use Net::HTTP to retrieve my yahoo mail.
I looked at the source html for the yahoo mail login page at:

On that page is a form with two form fields for obtaining the username
and password. Those form fields have the name attributes:


The form data is submitted to to the following url(which is specified in
the form’s action attribute):


I’m using the following general format for posting form data with ruby
1.8.2, which I got from the comments at the top of net/http.rb:

require “net/http”
require “uri”

url = URI.parse(“Yahoo”)

Net::HTTP.start(“”, 80) do |http|
headers2 = {“Host”, “”}

response ="/config/login?", "login=me&passwd=pword",


puts response.message
puts response.code
response.each_header do |header, val|
    puts "#{header}: #{val}"


During testing, I found out that if I didn’t specify a hash containing
headers, I would get a Bad Request error:

Bad Request

With some further testing, I discovered that the Host header is the only
one that is necessary to get a response. Here is the output from the

connection: close
content-type: text/html; charset=UTF-8
date: Mon, 17 Sep 2007 23:11:06 GMT
server: Apache
content-length: 0

I get the same response output no matter what headers I include, e.g.:

headers = {“Accept”, “text/html”,
“Content Type”, “application/x-www-form-urlencoded”,
“Content-Length”, “40”,
“Host”, “

Here’s a description of a 302 response:

302 Found

The requested resource resides temporarily under a different URI. Since
the redirection might be altered on occasion, the client SHOULD continue
to use the Request-URI for future requests. This response is only
cacheable if indicated by a Cache-Control or Expires header field.

The temporary URI SHOULD be given by the Location field in the response.
Unless the request method was HEAD, the entity of the response SHOULD
contain a short hypertext note with a hyperlink to the new URI(s).

If the 302 status code is received in response to a request other than
GET or HEAD, the user agent MUST NOT automatically redirect the request
unless it can be confirmed by the user, since this might change the
conditions under which the request was issued.

I thought I would be able to get the Location header and proceed from
there. But I pasted the location url into my browser, and it’s an
earthlink error page. So, it seems something must be wrong with my

I’m not sure if I’m using the correct url for the Host header and
whether that may be the source of the problem. Can anyone point me in
the right direction to proceed from here? I created a yahoo mail
account just for testing this program, so feel free to use the account.
The login name and password are in the code.


7stud – wrote:

The login name and password are in the code.


Whoops. Here is the account info:

response ="/config/login?",