3

I have a very simple API, that I would like to make a POST to using ruby and NOT using a GEM just the built in libraries net/http, uri, and openssl if needed.

Anyway, I am using the code below to make a very simple POST request but am getting some VERY strange results and was hoping someone else has seen this.

I have also tested the same request below in POSTMAN and NodeJS and BOTH work as expected, the only one I can not get to work is Ruby.

require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://somesite.dev/devices")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["key"] = '1234567'

response = http.request(request)
puts response.read_body

The result is something I have not seen before: I am getting the header key twice... So the log to the API shows a query like this:

SELECT * FROM device where key = '1234567, 1234567' LIMIT ...

As stated above I can make the same request via POSTMAN or NodeJS and get the correct result.

NOTE: Because I have a local copy of the API I can test locally BUT it's not SSL it's all over http. When making the request locally it works just fine. So from what I can tell this issue only presents it self when SSL is introduced.

Any help would be amazing! Thanks!!

Ruby Version 2.2.1

gregwinn
  • 941
  • 1
  • 9
  • 16
  • Unless you are creating a new protocol, I'd recommend using one of the established [Ruby HTTP clients](https://www.ruby-toolbox.com/categories/http_clients), not Net::HTTP. Reinventing a wheel can waste a lot of time and cause a lot of frustration. Which to use is for you to determine. SSL can't cause this problem, it's merely a pipeline. Without a lot more code we can't really diagnose the problem, we can only guess; Perhaps the server-side API has a problem with its handling of the SSL side of the data. Reading "[ask]" and the linked pages, and "[mcve]" will help. – the Tin Man Dec 01 '16 at 21:36
  • The API has been checked and again, I can make the same request in POSTMAN or another programming language tested in NodeJS along with Curl and they all work as expected. I have tried using rest-client and get the same issue, so i wanted to back out of a GEM for now to see if I could figure out what is going on. – gregwinn Dec 01 '16 at 21:57
  • Well, consider it this way, the SSL pipe is tested extremely heavily by Rails and all sorts of other clients, so if there was a duplication of data occurring, or the data was coming out corrupted, it'd be happening all over the place and having problems with any systems the code talked to. We need to be able to duplicate the problem based on the code in your question, so we'll need more information. Your Ruby version is out of date, which would affect Ruby and its OpenSSL. Perhaps updating it will help. – the Tin Man Dec 01 '16 at 22:34

1 Answers1

0

The issue was with something I did not list in my initial question. The API was using AWS API Gateway, and HTTP_PROXY was enabled on the method causing this strange issue. After I removed HTTP_PROXY the issue cleared up and the above code worked!

gregwinn
  • 941
  • 1
  • 9
  • 16