-
Notifications
You must be signed in to change notification settings - Fork 4
Rubyでhttp通信内容を確認する
mechamogera edited this page Mar 1, 2014
·
5 revisions
-
以下の記事に引っ越しました、ここはもうメンテしません。
-
以下のような感じでnet/httpの通信内容を確認できる
-
initializeを再定義しているのはライブラリ中での通信も補足できるようにするため
require 'net/http'
class Net::HTTP
alias :create :initialize
def initialize(*args)
create(*args)
self.set_debug_output STDOUT
end
end
http = Net::HTTP.new("www.google.co.jp", 80)
p http.get("/").cod
- 以下のようなログが出力される
opening connection to www.google.co.jp...
opened
<- "GET / HTTP/1.1\r\nConnection: close\r\nHost: www.google.co.jp\r\nAccept: */*\r\n\r\n"
-> "HTTP/1.1 200 OK\r\n"
-> "Date: Sun, 30 Sep 2012 01:49:21 GMT\r\n"
-> "Expires: -1\r\n"
-> "Cache-Control: private, max-age=0\r\n"
-> "Content-Type: text/html; charset=Shift_JIS\r\n"
-> "Set-Cookie: PREF=ID=be9181a7dc77ebf4:FF=0:TM=1348969761:LM=1348969761:S=bvbJqDikB9M8WLUZ; expires=Tue, 30-Sep-2014 01:49:21 GMT; path=/; domain=.google.co.jp\r\n"
-> "Set-Cookie: NID=64=kBPaI8UJL-M-Q_EBwtwutN_hVKOV2JYL6w-2lNpNGya83gDk2bLmUu6IkvrSE3lbDbVCpxcDciGHcdcd0TxlOyIrT34AOJdo_gUALHHJ6aVu0O75QscfZkchFxPWO-3W; expires=Mon, 01-Apr-2013 01:49:21 GMT; path=/; domain=.google.co.jp; HttpOnly\r\n"
-> "P3P: CP=\"This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info.\"\r\n"
-> "Server: gws\r\n"
-> "X-XSS-Protection: 1; mode=block\r\n"
-> "X-Frame-Options: SAMEORIGIN\r\n"
-> "Connection: close\r\n"
-> "\r\n"
reading all...
-> "[GETしたbody]"
read 43792 bytes
Conn close