Reputation: 11649
I have this code finally working:
res = Net::HTTP.post_form(URI('http://jobcoin.gemini.com/protozoan/api/transactions'), {})
=> #<Net::HTTPBadRequest 400 Bad Request readbody=true>
res.body
=> "{\"error\":{\"amount\":[\"This field is required\"],\"fromAddress\":[\"This field is required\"],\"toAddress\":[\"This field is required\"]}}"
I am able to make the post request to the server even though I have an error.
readbody=true
mean?This does not work. Why? What does the error message mean?
Net::HTTP.post_form(URI('http://www.jobcoin.gemini.com/protozoan/api/transactions'), {})
SocketError: getaddrinfo: nodename nor servname provided, or not known
It seems like the www
causes this to fail. Why is this? When I visit the site via a browser, the site does not exist. I always thought the two (with the www and without the www
) were the same address. Is it not?
nodename
or socketerror
mean exactly?Upvotes: 0
Views: 369
Reputation: 4461
There are several things here:
#<Net::HTTPBadRequest 400 Bad Request readbody=true>
.
According to the response body you're missing some required
parameters.SocketError
means you're trying to connect to a non-existing host.Now to your questions:
readbody=true
means the server response was read. Check net/response.rb
line 197.SocketError
, nodename
and servname
refer to the domain name of the server.Hope it helps.
Upvotes: 1
Reputation: 15791
The message you get after executing post_form
is coming from the core ruby class which represents the http response:
def inspect
"#<#{self.class} #{@code} #{@message} readbody=#{@read}>"
end
This outputs the instance variable @read
which(if I understand correctly) is a flag telling if the body was read.
The second question is too broad. In short words you can serve www
or "naked domain" or both. Usually people redirect requests from www
to the "naked domain" or visa-versa. In your case seems like the server doesn't serve www
hence the error. The error message is pretty self-explanatory - "there is no node(computer) which serves this endpoint" -
read about sockets.
Upvotes: 1