post
parent
1dd6e72025
commit
62a178f0da
10
main.cr
10
main.cr
|
@ -2,11 +2,11 @@ require "./src/mechanize.cr"
|
|||
|
||||
agent = Mechanize.new
|
||||
agent.request_headers = HTTP::Headers{"Foo" => "Bar"}
|
||||
params = {"hoge" => "hoge"}
|
||||
page = agent.get("http://google.com/", params: params)
|
||||
#query = {"foo" => "foo_value", "bar" => "bar_value"}
|
||||
#page = agent.post("http//example.com/", query: query)
|
||||
#params = {"hoge" => "hoge"}
|
||||
#page = agent.get("http://example.com/", params: params)
|
||||
query = {"foo" => "foo_value", "bar" => "bar_value"}
|
||||
page = agent.post("http://example.com/", query: query)
|
||||
#puts page.code
|
||||
#puts page.body
|
||||
puts page.body
|
||||
#puts page.css("h1").first.inner_text
|
||||
#puts page.title
|
||||
|
|
|
@ -45,7 +45,7 @@ class Mechanize
|
|||
headers.merge!(content_headers)
|
||||
|
||||
# fetch the page
|
||||
page = @agent.fetch uri, :post, headers, [request_data]#, cur_page
|
||||
page = @agent.fetch(uri, :post, headers: headers, params: {"value" => request_data })#, cur_page
|
||||
#add_to_history(page)
|
||||
page
|
||||
end
|
||||
|
|
|
@ -30,7 +30,7 @@ module MechanizeCr
|
|||
when :get
|
||||
::HTTP::Client.get(uri, headers: request_headers)
|
||||
when :post
|
||||
#client.post(path)
|
||||
::HTTP::Client.post(uri, headers: request_headers, form: params.not_nil!.fetch("value", ""))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -47,6 +47,8 @@ module MechanizeCr
|
|||
query = URI::Params.encode(params)
|
||||
uri.query = query
|
||||
return uri, nil
|
||||
when :post
|
||||
return uri, params
|
||||
else
|
||||
return uri, params
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue