Reputation: 1817
I have a program that sends an HTTP request and receive the answer.
http = Net::HTTP.new(server, port)
resp, data = http.post(path, url, headers)
After this I see resp with a value of #<Net::HTTPOK:0x00005643dd572980>
and data empty, so I receive a
no implicit conversion of nil into String
error afterwards when I use it.
I have never used Ruby so I'm a bit confused about what can be failing or how I can debug this. I capture network traffic and both the request and response are sent correctly, and the response contains the expected data.
Is there anything that can make data
be empty? How can I debug this?
Upvotes: 0
Views: 79
Reputation: 1173
Per the documentation, the Net::HTTP
post
method returns an HTTPResponse
object. Since there is only one object returned, only resp
will be given a value.
You mentioned that "the response contains the expected data." I am wondering if you simply need to employ the body
method. Does resp.body
give you the data you are looking for?
See https://ruby-doc.org/stdlib-2.7.1/libdoc/net/http/rdoc/Net/HTTP.html#method-i-post
Upvotes: 2