Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby post请求失败,getaddrinfo错误_Ruby_Sockets_Http_Soap - Fatal编程技术网

Ruby post请求失败,getaddrinfo错误

Ruby post请求失败,getaddrinfo错误,ruby,sockets,http,soap,Ruby,Sockets,Http,Soap,我正在尝试向易趣的web服务发送SOAP POST请求,以添加项目请求: require 'uri' require 'net/https' # Create the http object http = Net::HTTP.new('https://api.sandbox.ebay.com', 443) http.use_ssl = true path = '/wsapi?callname=AddItem&siteid=0&v

我正在尝试向易趣的web服务发送SOAP POST请求,以添加项目请求:

    require 'uri'
    require 'net/https'


    # Create the http object
    http = Net::HTTP.new('https://api.sandbox.ebay.com', 443)
    http.use_ssl = true
    path = '/wsapi?callname=AddItem&siteid=0&version=733&Routing=new'

    # Create the SOAP Envelope
data = <<-eot
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ebay:apis:eBLBaseComponents">
   <soapenv:Header>
      <urn:RequesterCredentials>
         <urn:eBayAuthToken>TOKEN HERE</urn:eBayAuthToken>
         <urn:Credentials>
            <urn:AppId>APP_ID</urn:AppId>
            <urn:DevId>DEV_ID</urn:DevId>
            <urn:AuthCert>AUTH_CERT</urn:AuthCert>
         </urn:Credentials>
      </urn:RequesterCredentials>
   </soapenv:Header>
   <soapenv:Body>
      <urn:AddItemRequest>
         <urn:DetailLevel>ReturnAll</urn:DetailLevel>
         <urn:ErrorLanguage>en_US</urn:ErrorLanguage>
         <urn:Version>733</urn:Version>
      </urn:AddItemRequest>
   </soapenv:Body>
</soapenv:Envelope>
eot

# Set Headers
header = {
  'Accept-Encoding' => 'gzip,deflate',
  'Content-Type' => 'text/xml;charset=UTF-8',
  'Host' => 'api.sandbox.ebay.com',
  'Connection' => 'Keep-Alive',
  'SOAPAction' => '',
  'Content-Lenth' => '160000',
  "X-EBAY-SOA-MESSAGE-PROTOCOL" => "SOAP12", 
  "X-EBAY-SOA-SECURITY-APPNAME" => "APP_ID_HERE"}

# Post the request
resp, data_end = http.post(path, data, header)

# Output the results
puts 'Code = ' + resp.code
puts 'Message = ' + resp.body
resp.each { |key, val| puts key + ' = ' + val }
puts data_end
require'uri'
需要“net/https”
#创建http对象
http=Net::http.new('https://api.sandbox.ebay.com', 443)
http.use_ssl=true
path='/wsapi?callname=AddItem&siteid=0&version=733&Routing=new'
#创建SOAP信封
data='text/xml;字符集=UTF-8',
'Host'=>'api.sandbox.ebay.com',
“连接”=>“保持活动状态”,
“SOAPAction'=>”,
“内容长度”=>“160000”,
“X-EBAY-SOA-MESSAGE-PROTOCOL”=>“SOAP12”,
“X-EBAY-SOA-SECURITY-APPNAME”=>“APP\u ID\u HERE”}
#发布请求
resp,data_end=http.post(路径、数据、头)
#输出结果
将“代码=”与相应的代码相加
将“Message=”和相应的正文放在一起
每个{|键,val |放置键+'='+val}
将数据放在末尾
我让它在瞬间工作。现在,每当我在Ubuntu的终端上运行IRB中的代码时,我总是收到一个getaddrinfo错误

我在玩创建套接字的游戏,我想这就是我如何让它工作的。但当我试图重新创建套接字时,我无法再复制结果

是否有更好的环境来启动此代码?我应该把插座弄得一团糟吗


Ruby不是在HTTP请求中内置了这种配置吗?如果套接字是其中很大的一部分,那么我应该研究什么样的主题呢?有没有好的资源可以告诉我如何设置套接字连接?

Net::HTTP.new的第一个参数是主机名或IP地址。您提供了一个URI。Ruby正在尝试解决”http://...“作为使用DNS的主机名,它失败了

将该行替换为:

http = Net::HTTP.new('api.sandbox.ebay.com', 443)

。。。它是有效的。(或者至少它已经超越了那个错误。)

你有没有调查过?据我所知,这是Ruby上仅存的SOAP宝石。您得到的确切错误是什么?getaddrinfo听起来像是dns问题。主机是否在ruby之外解析?确切的错误如下:“SocketError:getaddrinfo:Name或service未知”。。。我想我的问题是-这里发生了什么?这个错误是否源于我需要了解更多的东西?为了更好地理解并能够在将来诊断类似的问题,我应该把学习重点放在什么学科上?