[英]Get only response headers in em_http_request
如何在em_http_request中仅获取响应标头?
我尝试使用此代码:
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_variable_get(:'@conn').close
帮助我,但也许您知道更有趣的解决方案
如果您不需要正文, 则应执行HEAD
请求而不是GET
。 要终止事件循环,您需要显式调用EventMachine.stop
。
EventMachine.run do
http = EventMachine::HttpRequest.new('my_url').head
http.headers do |headers|
# do something with headers
EventMachine.stop
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.