Permalink
Browse files

Adding cookies example

  • Loading branch information...
1 parent b2ff0d8 commit 1ac7e60017081edeebf206c049cb707d6bd96045 @timurvaleev timurvaleev committed Apr 17, 2011
Showing with 25 additions and 0 deletions.
  1. +25 −0 cookies.rb
View
@@ -0,0 +1,25 @@
+require "net/http"
+require "uri"
+
+uri = URI.parse("http://translate.google.com/")
+http = Net::HTTP.new(uri.host, uri.port)
+
+# make first call to get cookies
+request = Net::HTTP::Get.new(uri.request_uri)
+
+response = http.request(request)
+
+# save cookies
+cookies = response.response['set-cookie']
+
+
+# make second call
+request = Net::HTTP::Get.new('/#auto|en|Pardon')
+
+# add previously stored cookies
+request['Cookie'] = cookies
+
+response = http.request(request)
+
+cookies = response.response['set-cookie'] # => nil
+

0 comments on commit 1ac7e60

Please sign in to comment.