net-http

Ruby - increasing proxy request timeout

Deadly 提交于 2019-12-08 03:08:08
问题 I'm trying to access some contents via some proxy servers but I get: <Errno::ETIMEDOUT: Connection timed out - connect(2)> I modified the code and tried to increase the timeout as below: require 'open-uri' require 'net/http' response = Net::HTTP::Proxy(proxy_ip, proxy_port).get_response(uri.host, uri.path) response.start(uri.host) do |http| http.open_timeout = 5 http.read_timeout = 10 end Now it doesn't recagnize the open_timeout and start undefined method `open_timeout=' for #<Net::HTTPOK

Setting an HTTP Timeout in Ruby 1.9.3

只谈情不闲聊 提交于 2019-12-07 15:30:55
问题 I'm using Ruby 1.9.3 and need to GET a URL. I have this working with Net::HTTP , however, if the site is down, Net::HTTP ends up hanging. While searching the internet, I've seen many people faced similar problems, all with hacky solutions. However, many of those posts are quite old. Requirements: I'd prefer using Net::HTTP to installing a new gem. I need both the Body and the Response Code. (e.g. 200) I do not want to require open-uri , since that makes global changes and raises some security

Using NetHTTP within Rails to hit Rails

≡放荡痞女 提交于 2019-12-07 14:53:04
问题 We have a very unique use case where we want a Rails controller to access a route within the Rails app using Net::HTTP. Can this be done? I'm currently receiving a timeout when attempting to do so. The current code works when the uri is a separate Rails app, but not when the uri belongs to the app itself. Here's the gist of the current controller action: def export_data uri = URI("http://localhost:3000") @data = JSON.parse( Net::HTTP.get(uri) ) respond_to do |format| ... end end Forget why we

Why do I get “Errno::ECONNREFUSED” with 'net/http' in Rails?

隐身守侯 提交于 2019-12-07 03:58:32
问题 I am trying to parse an XML file from a URL. When I try something like this: require 'net/http' require 'rubygems' require 'xmlsimple' url = 'http://my-address.com/xmltest/note.xml' xml_data = Net::HTTP.get_response(URI.parse(url)).body Everything works, but only when I do this outside of my Rails project. If I try including this file in my Rails 3 project and parsing it there, I get the error "Errno::ECONNREFUSED in [controller]" - Connection refused - connect(2) . My problem is the

Ruby - increasing proxy request timeout

穿精又带淫゛_ 提交于 2019-12-06 09:50:59
I'm trying to access some contents via some proxy servers but I get: <Errno::ETIMEDOUT: Connection timed out - connect(2)> I modified the code and tried to increase the timeout as below: require 'open-uri' require 'net/http' response = Net::HTTP::Proxy(proxy_ip, proxy_port).get_response(uri.host, uri.path) response.start(uri.host) do |http| http.open_timeout = 5 http.read_timeout = 10 end Now it doesn't recagnize the open_timeout and start undefined method `open_timeout=' for #<Net::HTTPOK 200 OK readbody=true>> undefined method `start.. Any help? When you call get_response on the Proxy(HTTP)

Why do I get Net::HTTP “request path is empty” error?

自古美人都是妖i 提交于 2019-12-06 08:19:27
问题 I'm using Net::HTTP to make a HTTP request. I get the error "HTTP request path is empty", but I strongly feel that it is not. The code is below: REQUEST_IP = "localhost" REQUEST_PORT = "8081" REQUEST_PATH = "myweb/rest" def customServiceMailAndMessageRequest user_id, message url = 'http://' + REQUEST_IP + ":" + REQUEST_PORT + "/" + REQUEST_PATH + '/users/' + user_id + '/messages/sendMailAndMessage?message=' + message uri = URI(url) request = Net::HTTP::Get.new(uri.path) request['Content-Type'

Uploading a file using ruby Net:HTTP API to a remote apache server failing with 409 Conflict

若如初见. 提交于 2019-12-06 05:13:11
Below is a program to upload a file from local file system to a remote Apache server. The program ends with a 409 conflict error. Is there any advice what am I doing wrong? I turned DAV on in httpd.conf and gave all necessary permissions, but I still had no luck. I can post the httpd.conf should it be needed. This is the code: BOUNDARY = "AaB03xZZZZZZ11322321111XSDW" uri = URI.parse("http://localhost/dropbox/") file = "/tmp/KEYS.txt" http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Put.new(uri.request_uri) request.body_stream=File.open(file) request["Content-Type"] = "multipart

Adjusting timeouts for Nokogiri connections

跟風遠走 提交于 2019-12-06 04:41:04
Why nokogiri waits for couple of secongs (3-5) when the server is busy and I'm requesting pages one by one, but when these request are in a loop, nokogiri does not wait and throws the timeout message. I'm using timeout block wrapping the request, but nokogiri does not wait for that time at all. Any suggested procedure on this? # this is a method from the eng class def get_page(url,page_type) begin timeout(10) do # Get a Nokogiri::HTML::Document for the page we’re interested in... @@doc = Nokogiri::HTML(open(url)) end rescue Timeout::Error puts "Time out connection request" raise end end # this

Persistent Ruby segfaulting after a clean install

心已入冬 提交于 2019-12-06 01:49:42
Ruby keeps segfaulting when using the Koala gem to talk over HTTP: /Users/pawel/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:799: [BUG] Segmentation fault I've tried the following: Run which -a ruby which showed multiple Rubies via MacPorts. So I deleted those and running the same command again returns only /usr/bin/ruby I've removed the MacPorts version of PostgreSQL and installed it with Homebrew instead (With MacPorts, it installs its own version of OpenSSL) Running openssl version returns OpenSSL 1.0.0g 18 Jan 2012 I removed Ruby 1.9.3 from RVM and tried Luciano's method below

Why do I get “Errno::ECONNREFUSED” with 'net/http' in Rails?

对着背影说爱祢 提交于 2019-12-05 07:51:39
I am trying to parse an XML file from a URL. When I try something like this: require 'net/http' require 'rubygems' require 'xmlsimple' url = 'http://my-address.com/xmltest/note.xml' xml_data = Net::HTTP.get_response(URI.parse(url)).body Everything works, but only when I do this outside of my Rails project. If I try including this file in my Rails 3 project and parsing it there, I get the error "Errno::ECONNREFUSED in [controller]" - Connection refused - connect(2) . My problem is the following: I don't know how to install the net/http component. I am looking for it on http://www.rubygems.org ,