是否可以使用Linux命令从HTTP服务器读取前N个字节?

这是问题。

给定URL http://www.example.com ,我们可以读取页面的前N个字节吗?

所以问题是我们怎样才能从HTTP服务器上读取前N个字节呢?

关心和感谢

curl <url> | head -c 499 

要么

 curl <url> | dd count=499 

应该做

也有更简单的使用情况,也许像Borader的可用性

  netcat host 80 <<"HERE" | dd count=499 of=output.fragment GET /urlpath/query?string=more&bloddy=stuff HERE 

要么

 GET /urlpath/query?string=more&bloddy=stuff 

您可以通过下一个curl命令本地执行此操作(不需要整个文档)。 根据culr手册页:

范围HTTP 1.1引入了字节范围。 使用这个,客户端可以请求只获取指定文档的一个或多个子部分。 curl-r标志支持这个。

 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应用程序,它也适用于我。

你也应该知道许多HTTP / 1.1服务器没有启用这个功能,所以当你试图获得一个范围时,你会得到整个文档。

无论如何,你必须得到整个网页,例如,你可以用卷曲的方式得到网页,然后用管道把它卷起来。

c,–bytes = [ – ] N打印每个文件的前N个字节; 用“ – ”开头,打印每个文件的最后N个字节

建立一个套接字连接。 读取你想要的字节。 关闭,你就完成了。