使用Ruby将XML请求发布到Web服务器

我担心我在Web服务器上发布文档(例如XML)的经验不多,所以如果我对HTTP的理解不足,我会道歉。

我在127.0.0.1端口2000上的ruby应用程序中设置了一个基本的Mongrel Web服务器。 (服务器)。

我在同一台计算机上运行一个单独的Ruby应用程序。 (客户端)。

我需要客户端将XML文档POST到服务器。

我曾尝试使用Net :: HTTP来做到这一点,但我找不到一个明确的例子,告诉我应该做些什么。 我有一个去,但遇到了错误。 我已经打破了请求,使其尽可能基本:

 http = Net::HTTP.new("127.0.0.1", 2000) http.post('file', 'query=foo') #xc.rb line 6 

但它会导致以下错误

  C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:141:in `read_nonblock': An existing connection was forcibly closed by the remote host. (Errno::ECONNRESET) from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:141:in `rbuf_fill' from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil' from C:/Ruby193/lib/ruby/1.9.1/net/protocol.rb:132:in `readline' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2562:in `read_status_line' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2551:in `read_new' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1319:in `block in transport_request' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1316:in `catch' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1293:in `request' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1286:in `block in request' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:745:in `start' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1284:in `request' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1307:in `send_entity' from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1096:in `post' from W:/Ruby/A/xc.rb:6:in `' 

我想我完全错了。 请你给我一个例子(或指向我的教程),让我发布一些基本数据,比如"text" 。 希望我能够设计出适当的标题并处理响应。

另外,我不需要使用net / http; 任何没有额外商业使用许可限制的免费方法都可以。

使用rest-client gem时,这非常容易

 require 'rest_client' response = RestClient.post "http://127.0.0.1:2000", "text", :content_type => "text/xml"