Class: AntiCaptcha::HTTP
- Inherits:
-
Object
- Object
- AntiCaptcha::HTTP
- Defined in:
- lib/anti_captcha/http.rb
Overview
AntiCaptcha::HTTP exposes common HTTP routines.
Class Method Summary collapse
-
.post_request(options = {}) ⇒ String
Performs a POST HTTP request.
Class Method Details
.post_request(options = {}) ⇒ String
Performs a POST HTTP request. Anti Captcha API supports only POST requests.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/anti_captcha/http.rb', line 18 def self.post_request( = {}) uri = URI([:url]) payload = [:json_payload] || '{}' timeout = [:timeout] || 60 headers = { 'User-Agent' => AntiCaptcha::USER_AGENT, 'Content-Type' => 'application/json' } req = Net::HTTP::Post.new(uri.request_uri, headers) req.body = payload http = Net::HTTP.new(uri.hostname, uri.port) http.use_ssl = true if (uri.scheme == 'https') http.open_timeout = timeout http.read_timeout = timeout res = http.request(req) res.body rescue Net::OpenTimeout, Net::ReadTimeout raise AntiCaptcha::Error.new('Request timed out.') end |