[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

retrieving yahoo! mail ?

7stud 7stud

9/17/2007 11:30:00 PM

Hi,

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:

https://login.yahoo.com/config/mai...

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

login
passwd

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

action="https://login.yahoo.com/config/lo...

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("https://login.yahoo.com/config/lo...)

Net::HTTP.start("https://login.yahoo..., 80) do |http|
headers2 = {"Host", "www.yahoo.com"}

response = http.post("/config/login?", "login=me&passwd=pword",
headers2)

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


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

Bad Request
400

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
response:

Found
302
connection: close
content-type: text/html; charset=UTF-8
date: Mon, 17 Sep 2007 23:11:06 GMT
server: Apache
content-length: 0
location:
http://earthlink-help.com/?AddInType=Bdns&Version=1.2.0el&FailureMode=1&ParticipantID=xj6e3468k634hy3945zg3zkhfn7zfgf6&ClientLocation=us&FailedURI=http%3A%2F%2Fwww.yahoo.com%2Fconfig%...

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", "www.yahoo.com"
}


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
request.

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.

Thanks.
--
Posted via http://www.ruby-....

1 Answer

7stud 7stud

9/18/2007 12:04:00 AM

0

7stud -- wrote:
> The login name and password are in the code.
>
> Thanks.

Whoops. Here is the account info:

response = http.post("/config/login?",
"login=rubytestmail&passwd=rubyruby")
--
Posted via http://www.ruby-....