curl是利用URL语法在命令行方式下工作的开源文件传输工具。
1.CURL + URL 获取当个网页源码,默认将输出打印到标准输出中。
curl www.baidu.com
2.CURL -o/-O选项保存下载的文件到指定的文件中。
-o: 将文件保存为命令中指定的文件名的文件。
-O: 使用URL中默认的文件名保存文件到本地。
curl -o baidu.com www.baidu.com #将文件下载到本地并且保存为baidu.com
curl -O www.baidu.com/index.php #使用url中默认的文件名将文件保存到本地
3.CURL -L 选项进行重定向
默认情况下,CURL不会发送HTTP Location headers,当一个被请求页面移动到另一个站点时,会发送一个HTTP Location header作为请求,然后重定向到新的地址上,例如,访问google时,会自动地将地址重定向到google.com.hk上:
curl -L http://www.google.com
使用-L强制重定向,此时会查询google.com.hk站点。
4.CURL -x 选项可以为curl添加代理
curl -x proxyserver.test.com:3182 http://www.baidu.com
5.CURL --data 选项使用POST请求
CURL默认使用GET方式请求数据,可以通过–data/-d方式指明使用POST方式传递数据。
GET:
curl -u username https://api.github.com/user?access_token=xxxxx
POST:
curl -u username --data "param1=value1¶m2=value" http://api.github.com
6.CURL 通过字典查询单词
查询单词的含义:
curl dict://dict.org/d:bash
250 ok
150 3 definitions retrieved
151 "Bash" gcide "The Collaborative International Dictionary of English v.0.48"
Bash \Bash\, v. t. [imp. & p. p. {Bashed}; p. pr. & vb. n.
{Bashing}.] [Perh. of imitative origin; or cf. Dan. baske to
strike, bask a blow, Sw. basa to beat, bas a beating.]
To strike heavily; to beat; to crush. [Prov. Eng. & Scot.]
--Hall Caine.
[1913 Webster]
Bash her open with a rock. --Kipling.
[Webster 1913 Suppl.]
.
151 "Bash" gcide "The Collaborative International Dictionary of English v.0.48"
Bash \Bash\, n.
1. a forceful blow, especially one that does damage to its
target.
[PJC]
2. a elaborate or lively social gathering or party.
[PJC]
.
151 "Bash" gcide "The Collaborative International Dictionary of English v.0.48"
Bash \Bash\, v. t. & i. [OE. baschen, baissen. See {Abash}.]
To abash; to disconcert or be disconcerted or put out of
countenance. [Obs.]
[1913 Webster]
His countenance was bold and bashed not. --Spenser.
[1913 Webster]
.
250 ok [d/m/c = 3/0/19; 0.000r 0.000u 0.000s]
221 bye [d/m/c = 0/0/0; 0.000r 0.000u 0.000s]
列出所有可用字典:文章来源:https://www.toymoban.com/news/detail-548178.html
curl dict://dict.org/show:db
250 ok
110 72 databases present
gcide "The Collaborative International Dictionary of English v.0.48"
wn "WordNet (r) 3.0 (2006)"
moby-thesaurus "Moby Thesaurus II by Grady Ward, 1.0"
elements "The Elements (07Nov00)"
vera "V.E.R.A. -- Virtual Entity of Relevant Acronyms (September 2014)"
jargon "The Jargon File (version 4.4.7, 29 Dec 2003)"
foldoc "The Free On-line Dictionary of Computing (18 March 2015)"
easton "Easton's 1897 Bible Dictionary"
hitchcock "Hitchcock's Bible Names Dictionary (late 1800's)"
bouvier "Bouvier's Law Dictionary, Revised 6th Ed (1856)"
devil "The Devil's Dictionary (1881-1906)"
world02 "CIA World Factbook 2002"
gaz2k-counties "U.S. Gazetteer Counties (2000)"
gaz2k-places "U.S. Gazetteer Places (2000)"
gaz2k-zips "U.S. Gazetteer Zip Code Tabulation Areas (2000)"
fd-tur-eng "Turkish-English FreeDict Dictionary ver. 0.2.1"
fd-por-deu "Portuguese-German FreeDict Dictionary ver. 0.1.1"
fd-nld-eng "Dutch-English Freedict Dictionary ver. 0.1.3"
fd-eng-ara "English-Arabic FreeDict Dictionary ver. 0.6.2"
fd-spa-eng "Spanish-English FreeDict Dictionary ver. 0.1.1"
fd-eng-hun "English-Hungarian FreeDict Dictionary ver. 0.1"
fd-ita-eng "Italian-English FreeDict Dictionary ver. 0.1.1"
...
7.CURL 授权
在访问需要授权的页面时,可通过使用-u选项提供用户名和密码进行授权。文章来源地址https://www.toymoban.com/news/detail-548178.html
curl -u username:password URL
通常的做法是在命令行中只输入用户名,之后会提示输入密码,这样可以保证在历史记录时不会将密码泄露。
curl -u username URL
到了这里,关于curl命令的使用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!