ruby - Can we see the request being sent with mechanise gem? -
i trying build request mechanize gem , keep getting redirects error. firstly want know if there's way of seeing actual request being sent after built different params?
@agent.verify_mode = openssl::ssl::verify_none cookie = mechanize::cookie.new('xyz_session', @tokenid) cookie.domain = ".mydomain.com" cookie.path = "/" @agent.cookie_jar << cookie @agent.redirection_limit=0 puts @agent.cookies body = {}.to_json #@agent.set_proxy("localhost",3000) @agent.request_headers = {'content-type' => "application/json"} @agent.get("https://access.test.api.mydomain.com/oidc/v1/user/authorise?response_type=code&redirect_uri=http://localhost&client_id=testclient1&service=accountsigninservice&state=any-state") expect(response.code).to eql(302), "authorization code couldn't received"
i keep getting redirect limit of 0 reached (mechanize::redirectlimitreachederror)
if not set redirection limit , connection refused: localhost:3000 (net::http::persistent::error)
hence want first check if request being sent way want be...
if not set redirection limit , connection refused: localhost:3000 (net::http::persistent::error)
i can duplicate error if there no server listening on port specified in ruby program. cure error, need start server listens on port 3000, e.g. netcat.
here's simple netcat command:
$ nc -l 3000
that tells netcat(nc) listen(-l) on port 3000. if run following ruby program in terminal window:
require 'mechanize' agent = mechanize.new cookie = mechanize::cookie.new("hello", "world") cookie.domain = "localhost" cookie.path = "/" agent.cookie_jar.add(cookie) agent.request_headers = {'content-type' => "application/json"} page = agent.get("http://localhost:3000/get_page")
the netcat window displays:
get /get_page http/1.1 accept-encoding: gzip,deflate,identity accept: */* user-agent: mechanize/2.7.4 ruby/2.3.0p0 (http://github.com/sparklemotion/mechanize/) accept-charset: iso-8859-1,utf-8;q=0.7,*;q=0.7 accept-language: en-us,en;q=0.5 cookie: hello=world host: localhost:3000 content-type: application/json connection: keep-alive keep-alive: 300
there lots of netcat recipes doing kinds of things on google.
Comments
Post a Comment