Ruby/Network/HTTPS
Материал из Wiki.crossplatform.ru
Содержание |
Get a secure way of sending sensitive information to the remote server:
require "net/http" require "net/https" url = URI.parse("https://example.ru/") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true if url.scheme == "https" request = Net::HTTP::Post.new(url.path) request.set_form_data({ "credit_card_number" => "1234123412341234" }) puts http.request(request).body
Making an HTTPS Web Request
require "net/https" # => true require "net/http" uri = URI.parse("https://www.yourDomain.gov/") request = Net::HTTP.new(uri.host, uri.port) response = request.get("/")
Secure HTTP with HTTPS
require "net/http" require "net/https" url = URI.parse("https://example.ru/") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true if url.scheme == "https" request = Net::HTTP::Get.new(url.path) puts http.request(request).body
Set verify mode for https
require "net/https" require "net/http" uri = URI.parse("https://www.yourDomain.gov/") request = Net::HTTP.new(uri.host, uri.port) request.use_ssl = true request.verify_mode = OpenSSL::SSL::VERIFY_NONE response = request.get("/") response.body.size # => 6537
verify_mode = OpenSSL::SSL::VERIFY_PEER
require "net/https" require "net/http" uri = URI.parse("https://www.yourDomain.gov/") request = Net::HTTP.new(uri.host, uri.port) request.use_ssl = true request.ca_path = "/etc/ssl/certs/" request.verify_mode = OpenSSL::SSL::VERIFY_PEER response = request.get("/")