net-http

Net::HTTP get timeout in Ruby

為{幸葍}努か 提交于 2019-12-01 21:25:26
问题 How can I set a larger timeout in net/http? What I'm doing is this: rta = JSON.parse(Net::HTTP.get(URI(url))) I've tried: uri = URI(url) http = Net::HTTP.new(uri.host, uri.port) http.open_timeout = 5* 60 http.read_timeout = 5* 60 rta = JSON.parse(Net::HTTP.get(URI(url))) but it still doesn't work. 回答1: It looks like it probably isn't working because you're making your get call on the Class instead of the instance you created. Try changing that last line to: rta = JSON.parse(http.get(URI(url))

HTTPS request using Net::HTTP's block form — is it possible?

白昼怎懂夜的黑 提交于 2019-12-01 01:31:41
问题 To do a Net::HTTP https request without the block form you can do this: ... http = Net::HTTP.new(url.host, url.port) http.use_ssl = true ... But is there a way to tell Net::HTTP to use https when doing the block form? u = URI.parse(url) Net::HTTP.start(u.host, u.port) do |http| # if I put http.use_ssl = true here, ruby complains that this can't # be done becuase the sesion has already started resp = http.get(u.request_uri) end I'm on ruby 1.8.7 回答1: See the documentation for Net::HTTP.start

Ruby undefined method `bytesize' for #<Hash:0x2954fe8>

牧云@^-^@ 提交于 2019-11-30 14:42:01
问题 i have the following Ruby Code, for a tracking website in sandbox mode: require "net/http" require "net/https" require "uri" xml = <<XML <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><data appname="dhl_entwicklerportal" language-code="de" password="Dhl_123!" request="get-status-for-public-user"><data piece-code="00340433836536550280"></data></data> XML uri = URI('https://cig.dhl.de/services/sandbox/rest/sendungsverfolgung') nhttp = Net::HTTP.new(uri.host, uri.port) nhttp.use_ssl

Ruby undefined method `bytesize' for #<Hash:0x2954fe8>

馋奶兔 提交于 2019-11-30 11:49:28
i have the following Ruby Code, for a tracking website in sandbox mode: require "net/http" require "net/https" require "uri" xml = <<XML <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><data appname="dhl_entwicklerportal" language-code="de" password="Dhl_123!" request="get-status-for-public-user"><data piece-code="00340433836536550280"></data></data> XML uri = URI('https://cig.dhl.de/services/sandbox/rest/sendungsverfolgung') nhttp = Net::HTTP.new(uri.host, uri.port) nhttp.use_ssl=true nhttp.verify_mode=OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(uri) request.basic_auth

Getting Headers from a Ruby Net::HTTP Request before making the request

杀马特。学长 韩版系。学妹 提交于 2019-11-30 09:16:15
问题 In Ruby, how can I get hold of the HTTP Request Headers that will be sent by a net/http(s) or open-uri request BEFORE it actually makes the request. In some cases, headers are used when creating a signed string in a URI. Surely there is some way to acquire the request headers that will be sent. These should include the "Host:" header for example. 回答1: see http://ruby-doc.org/stdlib-2.0/libdoc/net/http/rdoc/Net/HTTP.html#label-Setting+Headers Works well in ruby 2.0.0 - but you are correct,

How to set a custom user agent in ruby

元气小坏坏 提交于 2019-11-30 08:14:07
I've a task to test different user agents on a URL through automation. I'm using ruby to code, and I've been trying to set an user agent using the following method, but it doesn't seem to recognize the user agent. @http = Net::HTTP.new(URL) response = @http.request_get(URL, {'User-Agent' => useragent}) Is there any other way to do this, or what am I doing wrong? http = Net::HTTP.new("your.site.com", 80) req = Net::HTTP::Get.new("/path/to/the/page.html", {'User-Agent' => 'your_agent'}) response = http.request(req) puts response.body Works great for me. Also another that work for me : require

Getting Headers from a Ruby Net::HTTP Request before making the request

痞子三分冷 提交于 2019-11-29 14:17:05
In Ruby, how can I get hold of the HTTP Request Headers that will be sent by a net/http(s) or open-uri request BEFORE it actually makes the request. In some cases, headers are used when creating a signed string in a URI. Surely there is some way to acquire the request headers that will be sent. These should include the "Host:" header for example. see http://ruby-doc.org/stdlib-2.0/libdoc/net/http/rdoc/Net/HTTP.html#label-Setting+Headers Works well in ruby 2.0.0 - but you are correct, different behavior in 1.9.3 Ruby 2.0.0 require 'net/http' uri = URI('http://github.com/ruby') http_request =

ruby net/http opening connection very slow

一个人想着一个人 提交于 2019-11-29 11:40:24
When I'm working with net/http in development it is extremely slow. I've installed net-http-spy gem to get some info about each request and I've found out that "opening connection" part takes the most time (more than 10 seconds). Further more, it doesn't keep connections alive, so it needs to reopen it on every request. opening connection to maps.google.com... # ~10 seconds opened Is there any way I could somehow improve the performance of net/http library by settings some of its defaults? I don't want a request specific fix, but something that would fix the issue globally. I'm using geokit

What is the difference between Ruby's 'open-uri' and 'Net:HTTP' gems?

久未见 提交于 2019-11-29 03:07:01
It seems like both of these gems perform very similar tasks. Can anyone give examples of where one gem would be more useful than the other? I don't have specific code that I'm referring to, I'm more wondering about general use cases for each gem. I know this is a short question, I will fill in the blanks upon request. Thanks. The reason they look like they perform similar tasks is OpenURI is a wrapper for Net::HTTP, Net::HTTPS, and Net::FTP. Usually, unless you feel you need a lower level interface, using OpenURI is better as you can get by with less code. Using OpenURI you can open a URL/URI

ruby net/http opening connection very slow

半腔热情 提交于 2019-11-28 04:39:20
问题 When I'm working with net/http in development it is extremely slow. I've installed net-http-spy gem to get some info about each request and I've found out that "opening connection" part takes the most time (more than 10 seconds). Further more, it doesn't keep connections alive, so it needs to reopen it on every request. opening connection to maps.google.com... # ~10 seconds opened Is there any way I could somehow improve the performance of net/http library by settings some of its defaults? I