简体   繁体   English

Net::HTTP 发送请求 xml

[英]Net::HTTP send request xml

I need to send the request in the form of xml.我需要以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)

When sending a request to the uri at the end of the method Net::HTTP::Post.new hooks port 80, as a result it turns out a connection on https://fs.example.com:8443/services/trust/13/usermixed:80 which leads to error 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.new在方法末尾向 uri 发送请求时, Net::HTTP::Post.new挂接端口 80,结果是https://fs.example.com:8443/services/trust/13/usermixed: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)

А similar problem is solved by the method Net::HTTP.post_form(uri, data) no ports at the end ... but it takes a date only by hash.一个类似的问题是通过方法Net::HTTP.post_form(uri, data) no ports at end 解决的......但它只需要一个哈希值的日期。 I need to send request.body to XML我需要将 request.body 发送到 XML

Thanks!谢谢!

When you want to start a new http session, let's use the base URL only, and send request to plain URL当你想开始一个新的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)

Then the request should work as expected.然后请求应该按预期工作。

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

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