Created
March 14, 2012 22:39
-
-
Save 3den/2040124 to your computer and use it in GitHub Desktop.
ssl request with net/http
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' | |
require 'net/https' | |
require 'uri' | |
def ssl_request(url, method, body, options={}) | |
options.reverse_merge!({ | |
"Content-Type" => "text/xml;application/soap+xml" | |
}) | |
uri = URI.parse(url) | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
request = case method.to_sym | |
when :post then Net::HTTP::Post.new(uri.request_uri) | |
when :put then Net::HTTP::Put.new(uri.request_uri) | |
when :delete then Net::HTTP::Delete.new(uri.request_uri) | |
else Net::HTTP::Get.new(uri.request_uri) | |
end | |
request.body = body | |
request["Content-Type"] = "text/xml;application/soap+xml" | |
response = http.request(request) | |
response.body | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot! This saved my life.