모든 것이 있지만 Hydra가받은 응답을 파헤쳐 야합니다. 예를 들어
: 여기
require 'typhoeus'
request = Typhoeus::Request.new(
'www.example.net',
method: :get,
headers: { Accept: 'text/html' }
)
hydra = Typhoeus::Hydra.hydra
hydra.queue(request)
hydra.run
는 응답이고 원래 요청입니다 내부 :
response = request.response
response.request
# => #<Typhoeus::Request:0x007f9093f9f288
# @base_url="www.example.net",
# @hydra=
# #<Typhoeus::Hydra:0x007f9093f9f0d0
# @max_concurrency=200,
# @memory={},
# @multi=
# #<Ethon::Multi:0x007f9093f9f030
# @easy_handles=[],
# @fd_excep=#<Ethon::Curl::FDSet:0x007f9093f9eba8>,
# @fd_read=#<Ethon::Curl::FDSet:0x007f9093f9ed60>,
# @fd_write=#<Ethon::Curl::FDSet:0x007f9093f9ec48>,
# @handle=#<FFI::AutoPointer address=0x007f9095c74740>,
# @max_fd=#<FFI::MemoryPointer address=0x007f9094f484d0 size=4>,
# @running_count=0,
# @timeout=#<FFI::MemoryPointer address=0x007f9094f3a7e0 size=8>, # !> instance variable @on_body not initialized
# @timeval=#<Ethon::Curl::Timeval:0x007f9093f9ee78>>,
# @options={},
# @queued_requests=[]>,
# @on_complete=[],
# @on_headers=[],
# @on_success=[],
# @options=
# {:method=>:get,
# :headers=>
# {"User-Agent"=>"Typhoeus - https://github.com/typhoeus/typhoeus",
# :Accept=>"text/html"},
# :maxredirs=>50},
# @original_options={:method=>:get, :headers=>{:Accept=>"text/html"}},
# @response=
# #<Typhoeus::Response:0x007f9093f97d08
# @options=
# {:httpauth_avail=>0,
# :total_time=>0.11088,
# :starttransfer_time=>0.110587,
# :appconnect_time=>0.0,
# :pretransfer_time=>0.053747,
# :connect_time=>0.053611,
# :namelookup_time=>0.001304,
# :effective_url=>"HTTP://www.example.net/",
# :primary_ip=>"93.184.216.34",
# :response_code=>200,
# :request_size=>121,
# :redirect_count=>0,
# :return_code=>:ok,
# :response_headers=>
# "HTTP/1.1 200 OK\r\nAccept-Ranges: bytes\r\nCache-Control: max-age=604800\r\nContent-Type: text/html\r\nDate: Tue, 30 Dec 2014 19:24:10 GMT\r\nEtag: \"359670651\"\r\nExpires: Tue, 06 Jan 2015 19:24:10 GMT\r\nLast-Modified: Fri, 09 Aug 2013 23:54:35 GMT\r\nServer: ECS (cpm/F9FC)\r\nX-Cache: HIT\r\nx-ec-custom-error: 1\r\nContent-Length: 1270\r\n\r\n",
# :response_body=>
# "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <style type=\"text/css\">\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 50px;\n background-color: #fff;\n border-radius: 1em;\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n body {\n background-color: #fff;\n }\n div {\n width: auto;\n margin: 0 auto;\n border-radius: 0;\n padding: 1em;\n }\n }\n </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n <p>This domain is established to be used for illustrative examples in documents. You may use this\n domain in examples without prior coordination or asking for permission.</p>\n <p><a href=\"http://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n",
# :debug_info=>
# #<Ethon::Easy::DebugInfo:0x007f9093f9de60 @messages=[]>},
# @request=#<Typhoeus::Request:0x007f9093f9f288 ...>>>
내부가 요청의 base_url
:
response.request.base_url
# => "www.example.net"
그리고 effective_url
:
내가 기억한다면 첫 번째 질문은 귀하가 요청한 것이며 두 번째는 리디렉션 처리 후, 즉 실제로 착륙 한 곳입니다.
고마워요! 그건 내가 찾고 있었던 100 % 였어. –