forked from nahi/httpclient
-
Notifications
You must be signed in to change notification settings - Fork 1
/
howto.rb
49 lines (39 loc) · 1.04 KB
/
howto.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env ruby
$:.unshift(File.join('..', 'lib'))
require 'httpclient'
proxy = ENV['HTTP_PROXY']
clnt = HTTPClient.new(proxy)
clnt.set_cookie_store("cookie.dat")
target = ARGV.shift || "http://localhost/foo.cgi"
puts
puts '= GET content directly'
puts clnt.get_content(target)
puts '= GET result object'
result = clnt.get(target)
puts '== Header object'
p result.header
puts "== Content-type"
p result.contenttype
puts '== Body object'
p result.body
puts '== Content'
print result.content
puts '== GET with Block'
clnt.get(target) do |str|
puts str
end
puts
puts '= GET with query'
puts clnt.get(target, { "foo" => "bar", "baz" => "quz" }).content
puts
puts '= GET with query 2'
puts clnt.get(target, [["foo", "bar1"], ["foo", "bar2"]]).content
clnt.debug_dev = STDERR
puts
puts '= GET with extra header'
puts clnt.get(target, nil, { "SOAPAction" => "HelloWorld" }).content
puts
puts '= GET with extra header 2'
puts clnt.get(target, nil, [["Accept", "text/plain"], ["Accept", "text/html"]]).content
clnt.debug_dev = nil
clnt.save_cookie_store