Can I pass the full Ruby Net :: HTTP request as a string before sending?

I am using Net::HTTP in Ruby 1.9.2p290 to handle some obviously network calls.

Now I need to see the full request that is sent to the server (as one long, large string corresponding to HTTP 1.0 / 1.1.

In other words, I want Net::HTTP handle the hard work of creating a standard HTTP request body request body, but I want to send a string using a custom delivery mechanism.

Net::HTTPRequest doesn't seem to have any useful methods here - do I need to go below the stack and Net::HTTPRequest ?

Does anyone know of a good library, perhaps besides Net :: HTTP, which might help?

EDIT: I would also like to do the same as in the other (turning the string response into Net::HTTP::* ), although it seems that I can create an instance of Net::HTTPResponse ?

+4
source share
1 answer

Inquiry:

 post = Net::HTTP::Post.new('http://google.com') post.set_form_data :query => 'ruby http' sio = StringIO.new post.exec si, Net::HTTP::HTTPVersion, post.path puts sio.string 

Answer:

 si = StringIO.new("HTTP/1.1 200 OK\n") bio = Net::BufferedIO.new(si) Net::HTTPResponse.read_new(bio) 
+2
source

Source: https://habr.com/ru/post/1413475/


All Articles