简体   繁体   English

传出帖子时TCP连接错误

[英]TCP connection error when outgoing post

I try to apply an sms api to my code to my system and stuck at posting data. 我尝试将sms api应用于我的代码至系统,并停留在发布数据上。 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) “在连接中的块中进行救援”:无法打开与https://rest-api.moceansms.com:443的 TCP连接(getaddrinfo:未知此类主机。)(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://”后即可正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM