Ruby 仅获取em_http_请求中的响应头
如何在em_http_请求中仅获取响应头 我尝试使用以下代码:Ruby 仅获取em_http_请求中的响应头,ruby,eventmachine,em-http-request,Ruby,Eventmachine,Em Http Request,如何在em_http_请求中仅获取响应头 我尝试使用以下代码: EventMachine.run do http = EventMachine::HttpRequest.new('my_url').get http.headers do |headers| Fiber.current.resume headers end end 但我不想接受整个身体。如何停止请求的执行? http.close不起作用 UPD http.instance\u variable\u get(:
EventMachine.run do
http = EventMachine::HttpRequest.new('my_url').get
http.headers do |headers|
Fiber.current.resume headers
end
end
但我不想接受整个身体。如何停止请求的执行?
http.close
不起作用
UPDhttp.instance\u variable\u get(:“@conn”).close对我有帮助,但如果您不想要主体,可能您知道更有趣的解决方案。要终止事件循环,需要显式调用
不是事件循环。只是请求。请参阅UPD+1,是的,HEAD请求是执行此操作的正确方法。当您执行HEAD
请求时,请求在定义接收到标头后结束。我假设在调用头
回调时,连接可能已经关闭。如果不想终止事件循环,只需删除EventMachine.stop
EventMachine.run do
http = EventMachine::HttpRequest.new('my_url').head
http.headers do |headers|
# do something with headers
EventMachine.stop
end
end