hah*_*ile 20 linux url command http
这是个问题.
给定网址http://www.example.com,我们可以读取页面外的前N个字节吗?
使用curl,有-r,0-499指定前500个字节.似乎解决了这个问题.
您还应该知道许多HTTP/1.1服务器没有启用此功能,因此当您尝试获取范围时,您将获得整个文档.
在python中使用urlib.类似的问题在这里,但根据康斯坦丁的评论,这是真的吗?
上次我尝试这种技术时失败了,因为实际上不可能只从HTTP服务器读取指定数量的数据,即你隐式读取所有HTTP响应,然后只读出它的前N个字节.所以最后你最终下载了整个1Gb恶意响应.
所以问题是我们如何在实践中从HTTP服务器读取前N个字节?
问候和谢谢
Ant*_*hov 18
您可以通过下一个curl命令本地执行此操作(无需下载整个文档).根据culr手册页:
范围HTTP 1.1引入了字节范围.使用此方法,客户端可以请求仅获取指定文档的一个或多个子部分.
curl用-r旗帜支持这个.Run Code Online (Sandbox Code Playgroud)Get the first 100 bytes of a document: curl -r 0-99 http://www.get.this/ Get the last 500 bytes of a document: curl -r -500 http://www.get.this/ `curl` also supports simple ranges for FTP files as well. Then you can only specify start and stop position. Get the first 100 bytes of a document using FTP: curl -r 0-99 ftp://www.get.this/README
即使使用部署到GigaSpaces的Java Web应用程序,它也适用于我.
curl <url> | head -c 499
Run Code Online (Sandbox Code Playgroud)
要么
curl <url> | dd bs=1 count=499
Run Code Online (Sandbox Code Playgroud)
应该做
还有更简单的工具,可能有borader可用性
netcat host 80 <<"HERE" | dd count=499 of=output.fragment
GET /urlpath/query?string=more&bloddy=stuff
HERE
Run Code Online (Sandbox Code Playgroud)
要么
GET /urlpath/query?string=more&bloddy=stuff
Run Code Online (Sandbox Code Playgroud)