curl命令是一个利用URL规则在命令行下工作的文件传输工具。它支持文件的上传和下载,所以是综合传输工具,但按传统,习惯称curl为下载工具。作为一款强力工具,curl支持包括HTTP、HTTPS、ftp等众多协议,还支持POST、cookies、认证、从指定偏移处下载部分文件、用户代理字符串、限速、文件大小、进度条等特征。命令语法curl(选项)(参数)命令选项Auseragentstring设置用户代理发送给服务器bcookienamestringfilecookie字符串或文件读取位置ccookiejarfile操作结束后把cookie写入到这个文件中Ccontinueatoffset断点续转Ddumpheaderfile把header信息写入到该文件中ereferer来源网址ffail连接失败时不显示http错误ooutput把输出写到该文件中Oremotename把输出写到该文件中,保留远程文件的文件名rrangerange检索来自HTTP1。1或FTP服务器字节范围ssilent静音模式。不输出任何东西Tuploadfilefile上传文件uuseruser〔:password〕设置服务器的用户和密码wwriteout〔format〕什么输出完成后xproxyhost〔:port〕在给定的端口上使用HTTP代理progressbar进度条显示当前的传送状态文件下载curl命令可以用来执行下载、发送各种HTTP请求,指定HTTP头部等操作curl是将下载文件输出到stdout,将进度信息输出到stderr,不显示进度信息使用silent选项。curlhttps:rumenz。comsilent下载文件到指定的文件小写o,大写O保存文件和它的原始文件名curlhttps:rumenz。com1。htmlo2。html 大写O保存文件和它的原始文件名curlhttps:rumenz。com1。htmlO progress显示进度条curlhttps:rumenz。com2。htmlo2。htmlprogress断点续传curlOurumenz:testftp:rumenz。comjdk。tar。gz 然后你的连接突然断开,你可以用以下命令继续下载curlCOurumenz:testftp:rumenz。comjdk。tar。gz 注意断点续传的参数是C,要自动续传的话要使用C,否则需要手工指定断点的字节位置。伪造请求来源curlehttps:json。imhttps:rumenz。com 参照页是位于HTTP头部中的一个字符串,用来表示用户是从哪个页面到达当前页面的,如果用户点击网页A中的某个连接,那么用户就会跳转到B网页,网页B头部的参照页字符串就包含网页A的URL。也可以使用referer选项指定参照页字符串。 H参数可以通过直接添加标头Referer,达到同样效果curlHReferer:https:json。imhttps:rumenz。com设置请求headercurlHHost:rumenz。comHacceptlanguage:zhcnURLcurl的带宽控制curllimitrate200khttps:rumenz。com1。html用curl进行认证 使用curl选项u可以完成HTTP或者FTP的认证,可以指定密码,也可以不指定密码在后续操作中输入密码:curluuser:pwdhttps:rumenz。comcurluuserhttps:rumenz。com只打印响应头curlIhttps:rumenz。comHTTP1。1200OKServer:openresty1。19。3。1Date:Wed,02Jun202113:37:41GMTContentType:texthtml;charsetutf8Connection:keepalive使用curl模拟get请求 直接显示网页内容curlhttps:json。im1。txt123456 显示请求头和网页内容curlihttps:json。im1。txtHTTP1。1200OKServer:openrestyDate:Wed,02Jun202114:02:30GMTContentType:textplainContentLength:8LastModified:Wed,02Jun202114:00:57GMTConnection:keepaliveETag:60b78f198AcceptRanges:bytes123456 直接显示网页内容curllhttps:json。im1。txt 显示get请求全过程解析curlvhttps:json。im1。txt 使用curl模拟post请求curldparam1value1m2value2https:json。imlogincurldloginrumenzpassword123XPOSThttps:json。imlogincurldloginrumenzdpassword123XPOSThttps:json。imlogin dataurlencode参数等同于d,发送POST请求的数据体,区别在于会自动将发送的数据进行URL编码。curldataurlencodecommenthelloworldhttps:json。imlogin上传文本文件curlddata。txthttps:json。imuploadpostjson格式的数据curllHContenttype:applicationjsonXPOSTd{rumenz:123}https:json。im123。json向服务器发送Cookiecurlhttps:json。imcookieuserrumenzpass123456Cookie写入到一个文件curlccookies。txthttps:json。im上传二进制文件 F参数用来向服务器上传二进制文件。curlFfile123。pnghttps:json。imuploadfile 上面命令会给HTTP请求加上标头ContentType:multipartformdata,然后将文件123png作为file字段上传。 F参数可以指定MIME类型。curlFfile123。png;typeimagepnghttps:json。imuploadfile 上面命令指定MIME类型为imagepng,否则curl会把MIME类型设为applicationoctetstream。 F参数也可以指定文件名。curlFfile123。png;filenamerumenz。pnghttps:json。imuploadfile 上面命令中,原始文件名为123。png,但是服务器接收到的文件名为rumenz。png。请求跟随服务器的重定向 L参数会让HTTP请求跟随服务器的重定向。curl默认不跟随重定向。curlLdrumenz123https:json。im调试参数 v参数输出通信的整个过程,用于调试。curlvhttps:json。im1。txtTrying150。109。147。28。。。TCPNODELAYsetConnectedtojson。im(150。109。147。28)port443(0)ALPN,offeringh2ALPN,offeringhttp1。1Cipherselection:ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:STRENGTHsuccessfullysetcertificateverifylocations:CAfile:etcsslcert。pemCApath:noneTLSv1。2(OUT),TLShandshake,Clienthello(1):TLSv1。2(IN),TLShandshake,Serverhello(2):TLSv1。2(IN),TLShandshake,Certificate(11):TLSv1。2(IN),TLShandshake,Serverkeyexchange(12):TLSv1。2(IN),TLShandshake,Serverfinished(14):TLSv1。2(OUT),TLShandshake,Clientkeyexchange(16):TLSv1。2(OUT),TLSchangecipher,Clienthello(1):TLSv1。2(OUT),TLShandshake,Finished(20):TLSv1。2(IN),TLSchangecipher,Clienthello(1):TLSv1。2(IN),TLShandshake,Finished(20):SSLconnectionusingTLSv1。2ECDHERSAAES128GCMSHA256ALPN,serveracceptedtousehttp1。1Servercertificate:subject:CNjson。imstartdate:Apr2714:50:232021GMTexpiredate:Jul2614:50:232021GMTsubjectAltName:hostjson。immatchedcertsjson。imissuer:CUS;OLetsEncrypt;CNR3SSLcertificateverifyok。GET1。txtHTTP1。1Host:json。imUserAgent:curl7。54。0Accept:HTTP1。1200OKServer:openrestyDate:Wed,02Jun202114:31:36GMTContentType:textplainContentLength:8LastModified:Wed,02Jun202114:00:57GMTConnection:keepaliveETag:60b78f198AcceptRanges:bytes123456Connection0tohostjson。imleftintact trace参数也可以用于调试,还会输出原始的二进制数据。curltracehttps:json。im 原文链接:https:rumenz。comrumenbijilinuxcurl。html