Last active
June 2, 2016 10:07
-
-
Save reyesyang/10ca2ab83ff23d1840c715e3907dbf2b to your computer and use it in GitHub Desktop.
Net::HTTP examples
This file contains 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
require 'net/http' | |
# Proxy | |
proxy_server = 'xxx.xxx.xxx.xxx' | |
proxy_port = 81 | |
## Example 1 | |
Net::HTTP.new('baidu.com', nil, proxy_server, proxy_port).start { |http| http.get '/' } | |
## Example 2 | |
Net::HTTP.start('baidu.com', nil, proxy_server, proxy_port) { |http| http.get '/' } | |
## Example 3 | |
## Ruby 1.9.3 以后不建议使用该方法 | |
proxy = Net::HTTP.proxy(proxy_server, proxy_port) | |
proxy.start('baidu.com') do { http| http.get '/' } | |
# SSL | |
## Example 1 | |
Net::HTTP.star('baidu.com', use_ssl: true) { |https| https.get '/' } | |
## Example 2 | |
https = Net::HTTP.new('baidu.com', 443) | |
https.use_ssl = true | |
https.start { |https| https.get '/' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment