我需要以xml的形式发送请求。
uri =URI('https://fs.example.com:8443/services/trust/13/usermixed')
http = Net::HTTP.new(uri)
request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/soap+xml; charset=UTF-8'
request.body = @body(as xml)
response = http.request(request)
当在方法结束时向uri发送请求时Net::HTTP::Post.new
挂钩端口80,结果在https://fs.example.com:8443/services/trust/13/usermixed:80
上发现了一个连接,导致错误SocketError: Failed to open TCP connection to https://fs.example.com:8443/services/trust/13/usermixed:80 (getaddrinfo: Name or service not known)
А类似的问题是通过Net::HTTP.post_form(uri, data)
方法解决的,最后没有端口...但是它只需要哈希日期。我需要将request.body发送到XML
谢谢!
如果要启动新的http
会话,请仅使用基本URL,并将请求发送到纯URL
uri = URI('https://fs.example.com:8443/services/trust/13/usermixed')
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.to_s)
request['Content-Type'] = 'application/soap+xml; charset=UTF-8'
request.body = @body(as xml)
response = http.request(request)
然后请求应该按预期工作。