Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 open-uri,我知道我可以使用如下元方法获取响应标头,但我想知道如何查看生成的 GET 标头。还是我必须为此使用不同的库?
page = open('http://www.google.com'); page.meta
page = open('http://www.google.com');
page.meta
谢谢您的帮助
您可以使用 设置请求参数open('http://example.com', 'User-Agent' => 'Me'),但要查看将发送的所有标头,您可能必须使用代理嗅探流量ngrep,或tcpflow。或者阅读源码。
open('http://example.com', 'User-Agent' => 'Me')
ngrep
tcpflow
open-uri是一个方便的库,用于通过网络快速获取和读取文件。如果这不是您的用例,您可以使用 Net::HTTP 等较低级别的库来获得对连接的更多控制。
open-uri