我正在尝试向 eBay 的 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
我让它工作了一瞬间。现在,每当我在 Ubuntu 终端上的 IRB 中运行代码时,我都会收到 getaddrinfo 错误。
我正在玩创建套接字,我认为这就是我让它工作的方式。但是当我尝试重新创建套接字时,我无法再复制结果。
是否有更好的环境来启动此代码?我应该完全弄乱套接字吗?
Ruby 不是在 HTTP 请求中内置了那种配置吗?如果套接字是其中很大一部分,我应该研究什么样的主题?有没有很好的资源可以告诉我如何设置套接字连接?