net-http

Add `Authorization Bearer` hash to Net::HTTP post request (Ruby)

半世苍凉 提交于 2021-01-27 06:59:23
问题 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: https://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html#class-Net::HTTP-label-Basic+Authentication I'm trying to replicate a curl that would look like: > curl 'http://localhost:8080/places' -d '{"_json":[{"uuid":"0514b...", > "name":"Athens"}]}' -X POST -H 'Content-Type: application/json' -H > 'Authorization: Bearer

Stream and unzip large csv file with ruby

做~自己de王妃 提交于 2020-05-25 04:56:40
问题 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 happen: Don't have to download the whole file before unzipping Don't have to unzip whole file before parsing csv lines Don't use up very much memory/disk while doing all this I don't know if that's possible or not. Here's what I was thinking: require 'open-uri'

Stream and unzip large csv file with ruby

北城余情 提交于 2020-05-25 04:56:13
问题 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 happen: Don't have to download the whole file before unzipping Don't have to unzip whole file before parsing csv lines Don't use up very much memory/disk while doing all this I don't know if that's possible or not. Here's what I was thinking: require 'open-uri'

How to set a proxy in rubys net/http?

半城伤御伤魂 提交于 2020-02-01 10:45:29
问题 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 = 8080 Net::HTTP.new('google.de', nil, proxy_addr, proxy_port).start { |http| # always proxy via your.proxy.addr:8080 Net::HTTP.get('google.de', '') } What am I doing wrong? Thanks for all answers! 回答1: Net::HTTP.new('google.de', nil, proxy_addr, proxy_port)

Persistent Ruby segfaulting after a clean install

橙三吉。 提交于 2020-01-13 14:05:21
问题 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

Persistent Ruby segfaulting after a clean install

懵懂的女人 提交于 2020-01-13 14:05:06
问题 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

How to search for exact matching string in a text file using Ruby?

[亡魂溺海] 提交于 2020-01-06 15:10:13
问题 I generated a text file having HTTP Request Response headers with response body. I want to search inside this file looking for response headers containing Access-Control-Allow-Origin: * as a header. The file contains this in the form of a line starting with -> and ending with " like this: -> "Access-Control-Allow-Origin: *\r\n" How can I search this text file and print a custom message above the request response headers using an if condition? Do I need some complex regex? With my code I can

Why don't I need to specify a CA bundle to Net::HTTP SSL requests?

我的未来我决定 提交于 2020-01-05 13:12:37
问题 A lot of what I've seen around SO and blog posts is that By default, Net::HTTP does not verify peer SSL certificates To force Net::HTTP to verify peer, you need to to it too and supply a CA cert file containing trusted authorities However, I've found that this is not completely necessary. On my Mac, I have the following code http = Net::HTTP.new('www.google.com', 443) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.start do http.request_get('/') do |response| puts

Why don't I need to specify a CA bundle to Net::HTTP SSL requests?

假如想象 提交于 2020-01-05 13:11:40
问题 A lot of what I've seen around SO and blog posts is that By default, Net::HTTP does not verify peer SSL certificates To force Net::HTTP to verify peer, you need to to it too and supply a CA cert file containing trusted authorities However, I've found that this is not completely necessary. On my Mac, I have the following code http = Net::HTTP.new('www.google.com', 443) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.start do http.request_get('/') do |response| puts

Rails 4 and Ruby 2 Net/HTTP SSL Request: OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol

江枫思渺然 提交于 2020-01-04 04:36:04
问题 This is nearly a duplicate of: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed but specific to a Rails 4 and Ruby 2 environment. I figure it is appropriate to make a new question because the solutions that worked on my machine for previous environments no longer appear to work after the updates to Rails and Ruby. The Problem When making a Net/HTTP SSL request to the tune of: api_uri = URI("http://accounts.google.com/o/oauth2/token") https = Net: