Questions tagged [net-http]

An HTTP client API for Ruby. Net::HTTP provides a rich library which can be used to build HTTP user-agents.

450 questions
47
votes
3 answers

Check Ruby HTTP response for success

How does one properly check the response from Net::HTTP::Get (for example) for "success" (i.e., a 2xx return code)? The documentation seems to be sadly silent on this simple question. I have: response=Net::HTTP.new( host, port ).request…
cbmanica
  • 3,502
  • 7
  • 36
  • 54
45
votes
6 answers

Ruby - net/http - following redirects

I've got a URL and I'm using HTTP GET to pass a query along to a page. What happens with the most recent flavor (in net/http) is that the script doesn't go beyond the 302 response. I've tried several different solutions; HTTPClient, net/http,…
r3nrut
  • 1,045
  • 2
  • 11
  • 28
44
votes
3 answers

OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server hello A

The code below yields the following error: OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server hello A require 'net/https' uri = URI.parse("https://.com") http = Net::HTTP.new(uri.host,…
Hesham
  • 2,327
  • 2
  • 20
  • 24
28
votes
5 answers

How to download an image file via HTTP into a temp file?

I've found good examples of NET::HTTP for downloading an image file, and I've found good examples of creating a temp file. But I don't see how I can use these libraries together. I.e., how would the creation of the temp file be worked into this code…
Dogweather
  • 15,512
  • 17
  • 62
  • 81
26
votes
1 answer

Sending a Post request with net/http

I need to send data in JSON to another app which runs on the same computer. I send request like so (rails 3.2.13 ) data = { //some data hash } url = URI.parse('http://localhost:6379/api/plans') resp, data = Net::HTTP.post_form(url, data.to_JSON…
Elmor
  • 4,775
  • 6
  • 38
  • 70
24
votes
4 answers

Ruby undefined method `bytesize' for #

i have the following Ruby Code, for a tracking website in sandbox mode: require "net/http" require "net/https" require "uri" xml = <
Crusader633
  • 595
  • 1
  • 4
  • 17
24
votes
2 answers

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

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. …
Richie Thomas
  • 3,073
  • 4
  • 32
  • 55
23
votes
5 answers

How to set a custom user agent in ruby

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 =…
rubytester
  • 339
  • 1
  • 3
  • 5
21
votes
2 answers

Rest APIs in Go - using net/http vs. a library like Gorilla

I see that Go itself has a package net/http, which is adequate at providing everything you need to get your own REST APIs up and running. However, there are a variety of frameworks; the most popular maybe say gorilla. Considering that one of the…
Ankur Garg
  • 2,553
  • 8
  • 30
  • 41
21
votes
5 answers

How to set a proxy in rubys net/http?

I'm trying to set a proxy and to use it in a simple get request like in the documentation. But I always receive an error! The adress and port are right with open-uri it worked.. it's http://proxy:8080 . proxy_addr = 'proxy' proxy_port =…
ada91
  • 828
  • 2
  • 7
  • 19
18
votes
2 answers

Process Management for the Go Webserver

I'm a new Go programmer, coming from the world of web application and service development. Apologies is this is a herp de-derp question, but my googling around for an answer hasn't found anything. Also, this is borderline Server Fault territory,…
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
15
votes
3 answers

Ruby using namespace/module

For example: require 'net/http' uri = URI('http://example.com/some_path?query=string') Net::HTTP.start(uri.host, uri.port) do |http| request = Net::HTTP::Get.new uri response = http.request request # Net::HTTPResponse object end What is the…
w00d
  • 5,416
  • 12
  • 53
  • 85
12
votes
2 answers

Measure response time for a HTTP request using Ruby

I'm building a small website for personal use to test an API my company makes. My boss wants a website where we can enter a website, request a form using GET or POST, and the number of times to send the request. He wants the request logged, the time…
Squadrons
  • 2,467
  • 5
  • 25
  • 36
12
votes
1 answer

Ruby, Tor and Net::HTTP::Proxy

My apologies in advance if this is a noobish doubt: I want to use a proxy in my Ruby code to fetch a few web pages. And I want to be sneaky about it! So I am using Tor. I have Tor running, and I am able to use Net::HTTP.get(uri) as usual. But I…
Chthonic Project
  • 8,216
  • 1
  • 43
  • 92
11
votes
1 answer

What causes OpenSSL::SSL::SSLErrorWaitReadable "read would block"?

What does the OpenSSL::SSL::SSLErrorWaitReadable "read would block" mean? I am getting the error OpenSSL::SSL::SSLErrorWaitReadable with the message read would block. I think this is because of timeouts, but I can't find any documentation on the…
Automatico
  • 12,420
  • 9
  • 82
  • 110
1
2 3
29 30