An HTTP client API for Ruby. Net::HTTP provides a rich library which can be used to build HTTP user-agents.
Questions tagged [net-http]
450 questions
11
votes
1 answer
Stream and unzip large csv file with ruby
I have problem where I need to download, unzip, and then process line by line a very large CSV file. I think it's useful to give you an idea how large the file is:
big_file.zip ~700mb
big_file.csv ~23gb
Here's some things I'd like to…

ZombieDev
- 959
- 1
- 10
- 25
10
votes
1 answer
HTTPS request using Net::HTTP's block form -- is it possible?
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 =…

John Bachir
- 22,495
- 29
- 154
- 227
9
votes
1 answer
Using Ruby to post an XML request to a webserver
I'm afraid I've not got much experience with posting documents (e.g. XML) over web-servers, so I apologise if my understanding of HTTP is lacking.
I have a basic Mongrel web server set up in a ruby app on 127.0.0.1 port 2000. (The server).
I am…

SimonMayer
- 4,719
- 4
- 33
- 45
9
votes
1 answer
Ruby 1.8.7 and Net::HTTP: Making an SSL GET request with client cert?
I'm trying to fetch a resource via SSL using Net::HTTP. Here is the relevant code fragment:
req = Net::HTTP::Get.new(ContentURI.path)
https = Net::HTTP.new(ContentURI.host, ContentURI.port)
https.use_ssl = true
https.cert =…

RoUS
- 1,888
- 2
- 14
- 29
9
votes
1 answer
Why is Ruby failing to connect to my Tor network?
I’m using Ruby on Rails 4.2.7 on Mac El Capitan and just installed the Tor browser (v 6.0.4). I fired up my Tor browser, have verified its running by viewing a couple of web pages, but using this gem — https://github.com/dryruby/tor.rb , when I run…

Dave
- 15,639
- 133
- 442
- 830
8
votes
2 answers
Ruby: Blocking HTTP.new.start and dynamic HTTP(S)
I need an application to block an HTTP request so I had to add a couple of lines of code, the only piece I couldn't figure out was the statement if uri.scheme == 'https'; http.use_ssl = true is there a way I can set http/https in the current…

Jordon Bedwell
- 3,189
- 3
- 23
- 32
8
votes
1 answer
Add `Authorization Bearer` hash to Net::HTTP post request (Ruby)
How can I add Authorization Bearer to a POST request with Net::HTTP?
I can only find help for "basic authentication" in the documentation.
req.basic_auth 'user', 'pass'
Source:…

tim_xyz
- 11,573
- 17
- 52
- 97
8
votes
3 answers
Increase connect(2) timeout in RestClient / Net::HTTP on AWS Linux
I'm using rest-client to POST to a very slow web service. I'm setting timeout to 600 seconds, and I've confirmed that it's being passed down to Net::HTTP's @read_timeout and @open_timeout.
However, after about two minutes, I get a low-level timeout…

David Moles
- 48,006
- 27
- 136
- 235
8
votes
3 answers
How to execute a HEAD Request in GO?
I want to get the content length of a page using GO net/http? I can do this in terminal using curl -i -X HEAD https://golang.org and then check the content-length field.
user6583848
8
votes
3 answers
Ruby Net::HTTP responds with OpenSSL::SSL::SSLError "certificate verify failed" after certificate renewal
We recently renewed the SSL certificate of our site, and the following occurs on Mac OS El Capitan 10.11.3:
require 'net/http'
Net::HTTP.get URI('https://www.google.com')
# => "..."
# The site whose certificate got…

AmitA
- 3,239
- 1
- 22
- 31
8
votes
3 answers
how to set header['content-type']='application/json' in ruby
require 'net/http'
require 'rubygems'
require 'json'
url = URI.parse('http://www.xyxx/abc/pqr')
resp = Net::HTTP.get_response(url) # get_response takes an URI object
data = resp.body
puts data
this is my code in ruby, resp.data is giving me…

unknownbits
- 2,855
- 10
- 41
- 81
7
votes
1 answer
TypeError: can't convert Net::HTTPOK into String
I'm using net/http and json to geocode an address using google's Geocoding API. Here is where the error is being thrown:
response = Net::HTTP.get_response(URI.parse(url))
result = JSON.parse(response)
The response is of class Net::HTTPOK, but I…

Chris
- 11,819
- 19
- 91
- 145
7
votes
6 answers
How to make an HTTP request without waiting for the response in Ruby
I just want to hit a server from inside of my Rails controller, but not wait for the response. Is this possible? (without launching other threads I can't do that for performance reasons)

Mohamed Hafez
- 8,621
- 7
- 41
- 49
7
votes
1 answer
Generate XML dynamically and post it to a web service in Rails
I am currently developing a Rails app in which I need to dynamically send XML request to an external web service. I've never done this before and I a bit lost.
More precisely I need to send requests to my logistic partner when the status of an order…

ClemDoum
- 77
- 1
- 6
7
votes
3 answers
400 bad request in ruby but not curl
I'm trying to make a https post request in ruby and it works in curl, but I get a 400 bad request in ruby and I'm having trouble figuring out why.
Heres the ruby code:
require 'rubygems'
require 'net/https'
require 'uri'
require 'json'
uri =…

AdamB
- 3,101
- 4
- 34
- 44