Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print information about a NET:HTTPRequest for debug purposes?

Tags:

http

ruby

https

I'm new to Ruby coming from Java. I'm trying to make a http get request and I'm getting an http response code of 400. The service I'm calling over http is very particular and I'm pretty sure that my request isn't exactly correct. It'd be helpful to "look inside" the req object after I do the head request (below) to double check that the request_headers that are being sent are what I think I'm sending. Is there a way to print out the req object?

req = Net::HTTP.new(url.host, url.port) req.use_ssl = true  res = req.head(pathWithScope, request_headers)  code = res.code.to_i puts "Response code: #{code}" 

I tried this: puts "Request Debug: #{req.inspect}" but it only prints this: #<Net::HTTP www.blah.com:443 open=false>

like image 228
Upgradingdave Avatar asked Jan 24 '10 20:01

Upgradingdave


People also ask

What is a raw HTTP request?

The Raw HTTP action sends a HTTP request to a web server. How the response is treated depends on the method, but in general the status code and the response headers are returned in variables defined as part of the page load options.

What is a HTTP response body?

An HTTP response object typically represents the HTTP packet (response packet) sent back by Web Service Server in response to a client request. An HTTP Response contains: A status. Collection of Headers. A Body.

How do I log into WebRequest?

1 var request = WebRequest. Create("http://www.conquerclub.com/game.php?game=13025037"); 2 HttpWebResponse response = (HttpWebResponse)request. GetResponse(); 3 StreamReader reader = new StreamReader(response.


1 Answers

Use set_debug_output.

http = Net::HTTP.new(url.host, url.port) http.set_debug_output($stdout) # Logger.new("foo.log") works too 

That and more in http://github.com/augustl/net-http-cheat-sheet :)

like image 75
August Lilleaas Avatar answered Sep 19 '22 03:09

August Lilleaas