Last active
December 15, 2015 05:19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# API v1.1, HTTPS | |
# Expected: {\"errors\":[{\"message\":\"Bad Authentication data\",\"code\":215}]} | |
# Raises: EOFError: end of file reached | |
require 'net/http' | |
uri = "https://api.twitter.com/1.1/users/show.json?user_id=33978" | |
Net::HTTP.get(URI(uri)) | |
# API v1, HTTPS | |
# Expected: {\"errors\":[{\"message\":\"Bad Authentication data\",\"code\":215}]} | |
# Raises: EOFError: end of file reached | |
require 'net/http' | |
uri = "https://api.twitter.com/1/users/show.json?user_id=33978" | |
Net::HTTP.get(URI(uri)) | |
# API v1.1, HTTP | |
# Expected: {\"errors\":[{\"message\":\"Bad Authentication data\",\"code\":215}]} | |
# Returns: {\"errors\":[{\"message\":\"Bad Authentication data\",\"code\":215}]} | |
require 'net/http' | |
uri = "http://api.twitter.com/1.1/users/show.json?user_id=33978" | |
Net::HTTP.get(URI(uri)) | |
# API v1.0, HTTP | |
# Expected: {\"errors\":[{\"message\":\"Bad Authentication data\",\"code\":215}]} | |
# Returns: {\"errors\":[{\"message\":\"Bad Authentication data\",\"code\":215}]} | |
require 'net/http' | |
uri = "http://api.twitter.com/1/users/show.json?user_id=33978" | |
Net::HTTP.get(URI(uri)) |
I'm trying to figure out what Ruby is doing to send the request. I was able to get the following to work:
1.8.7 :001 > require 'net/https' => true
1.8.7 :002 > uri = URI.parse("https://api.twitter.com/1.1/users/show.json?user_id=33978") => #<URI::HTTPS:0x10cf8a090 URL:https://api.twitter.com/1.1/users/show.json?user_id=33978>
1.8.7 :003 > http = Net::HTTP.new(uri.host, uri.port, "localhost", 8080)
=> #<#<Class:0x10cf80388> api.twitter.com:443 open=false>
1.8.7 :004 > http.use_ssl = true
=> true
1.8.7 :005 > http.verify_mode = OpenSSL::SSL::VERIFY_PEER
=> 1
1.8.7 :006 > request = Net::HTTP::Get.new(uri.request_uri) => #<Net::HTTP::Get GET>
1.8.7 :007 > response = http.request(request)
=> #<Net::HTTPBadRequest 400 Bad Request readbody=true>
Note that I'm setting up a proxy using mitmproxy to capture the request. Interestingly, the difference between the request from the snippet above and the failing first example is that the working example sends:
GET https://api.twitter.com/1.1/users/show.json?user_id=33978
← 400 application/json 61B
But the failing ruby test sends:
GET http://api.twitter.com:443/1.1/users/show.json?user_id=33978
← Blank server response.
Note the http/https difference. It seems like Ruby is sending a non-HTTPS request to api.twitter.com:443 and just getting rejected at the SSL handshake part of the request.
Any idea of anything which may have changed recently with regard to how Net::HTTP sends requests?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notes
1.8.7-p371
,1.9.2-p320
, and1.9.3-p392
but not2.0.0-p0
.user_id=33978
).