Skip to content

Instantly share code, notes, and snippets.

@reyesyang
Last active June 2, 2016 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reyesyang/10ca2ab83ff23d1840c715e3907dbf2b to your computer and use it in GitHub Desktop.
Save reyesyang/10ca2ab83ff23d1840c715e3907dbf2b to your computer and use it in GitHub Desktop.
Net::HTTP examples
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