Recipe 14.1. Grabbing the Contents of a Web Page
Problem
You want to
display or process a specific web page.
Solution
The simplest solution is to use the
open-uri library. It lets you open a web page as though it were a file. This c...
Recipe 14.2. Making an HTTPS Web Request
Problem
You want to connect to an HTTPS web site, one whose traffic is encrypted using SSL.
Solution
You need the OpenSSL extension to Ruby. You'll know if it's installed if you can require th...
Recipe 14.3. Customizing HTTP Request Headers
Problem
When you make an HTTP request, you want to specify custom HTTP headers like "
User-Agent" or "
Accept-Language".
Solution
Pass in a Hash of header values to Net::HTTP#get or N...
Recipe 14.4. Performing DNS Queries
Problem
You want to find the IP address corresponding to a domain name, or see whether a domain provides a certain service (such as an email server).
Solution
Use the Resolv::
DNS class in the st...
Recipe 14.5. Sending Mail
Problem
You want to send an email message, either an autogenerated one or one entered in by an end user.
Solution
First you need to turn the parts of the email message into a single string, representing the ...
Recipe 14.6. Reading Mail with IMAP
Credit: John Wells
Problem
You want to connect to an
IMAP server in order to read and manipulate the messages stored there.
Solution
The
net/imap.rb package, written by Shugo Maeda, is part ...
Recipe 14.7. Reading Mail with POP3
Credit: John Wells
Problem
You want to connect to an POP server in order to read and download the messages stored there.
Solution
The
net/pop.rb package, written by Minero Aoki, is part of Ruby...
Recipe 14.8. Being an FTP Client
Problem
You want to automatically connect to an FTP server, and upload or download files.
Solution
Use the
Net::FTP class. It provides a filesystem-like interface to an FTP server. In this example,...
Recipe 14.9. Being a Telnet Client
Problem
You want to connect to a telnet service or use telnet to get low-level access to some other kind of server.
Solution
Use the
Net::Telnet module in the Ruby standard library.
The followin...
Recipe 14.10. Being an SSH Client
Problem
You want to securely send data or commands back and forth between your computer, and another computer on which you have a shell account.
Solution
Use the
Net::SSH module, which implements the S...
Recipe 14.11. Copying a File to Another Machine
Problem
You want to programatically send files to another computer, the way the Unix scp command does.
Solution
Use the
Net:SSH library to get a secure shell connection to the other ...
Recipe 14.12. Being a BitTorrent Client
Problem
You want to write a Ruby script that downloads or shares large files with
BitTorrent.
Solution
The third-party RubyTorrent library implements the BitTorrent protocol; you can use it ...
Recipe 14.13. Pinging a Machine
Problem
You want to check whether a particular machine or domain name can be reached from your computer.
Solution
Use Ruby's standard
ping library. Its single method,
Ping.pingecho, TRies to get ...
Recipe 14.14. Writing an Internet Server
Problem
You want to run a server for a TCP/IP application-level protocol, but no one has written a Ruby server for the protocol yet. This may be because it's a protocol you've made up.
Solution...
Recipe 14.15. Parsing URLs
Problem
You want to parse a string representation of a URL into a data structure that articulates the parts of the URL.
Solution
URI.parse TRansforms a string describing a URL into a URI object.[5] ...
Recipe 14.16. Writing a CGI Script
Credit: Chetan Patil
Problem
You want to expose Ruby code through an existing web server, without having to do any special configuration.
Solution
Most web servers are set up to run CGI
scripts,...
Recipe 14.17. Setting Cookies and Other HTTP Response Headers
Credit: Mauro Cicio
Problem
You're
writing a CGI program and you want to customize the HTTP headers you send in response to a request. For instance, you may want to set...
Recipe 14.18. Handling File Uploads via CGI
Credit: Mauro Cicio
Problem
You want to let a visitor to your web site upload a file to the web server, either for storage or processing.
Solution
The CGI class provides a simple interface...
Recipe 14.19. Running Servlets with WEBrick
Credit: John-Mason Shackelford
Problem
You want to embed a server in your Ruby application. Your project is not a traditional web application, or else it's too small to justify the use of a...
С 2009 года мы стали переводить структура сайта на различные языки. Сайт теперь будет содержать книги не только на английском языке, но также и на других европейских языках, в том числе и на Русском языке.