I try to apply an sms api to my code to my system and stuck at posting data. I followed the sample code found online to post the data, but getting the error at below. I'm sure the host is valid and my internet connection is fine.
`rescue in block in connect': Failed to open TCP connection to https://rest-api.moceansms.com:443 (getaddrinfo: No such host is known. ) (SocketError)
Below is my code
require "net/http"
url = 'https://rest-api.moceansms.com'
uri = '/rest/1/sms'
params = {'mocean-api-key'=>'mykey','mocean-api-secret'=>'secret','mocean-to'=>'60162211800','mocean-from'=>'63001','mocean-text'=>'Hello world!!!'}
begin
http = Net::HTTP.new(url,443)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
if params.size > 0
request.form_data = params
end
puts http.request(request)
rescue Exception
raise Exception.new('Unable connect to host')
end
由于网址中包含“ https://”而导致的错误,从网址中删除“ https://”后即可正常工作
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.