浏览自动化上传相关文章的时候,发现了curl命令,突然豁然开朗,上传下载方便的一塌糊涂,可以媲美postman了.
curl使用gitbook地址
记录下curl使用的几个重要参数,curl的参数是大小写敏感的,可简写 如:-v,可全拼如:--verbose
-
-v或--verbose, 输出详细内容 (注意v是小写)
curl -v https://www.baidu.com
-V或--version输出当前curl的版本信息
curl -V https://www.baidu.com
-
-d或者--data用此参数就默认使用POST方法-
-d json传递的是json参数
curl -d '{ "name": "Darth" }' http://example.com-
-d @filePath@+fliename, 上传文件
curl -d @fileName.txt http://example.com-
-d "key=value&key2=value2",参数的是键值对的字符串,通过&连接多个参数,也可以分开写如:-d "key=value" -d "key2=value2"
curl -d 'name=admin&shoesize=12'http://example.com/ curl -d name=admin -d shoesize=12 http://example.com/-
--data-binarypost上传二进制的文件
curl --data-binary @filename http://example.com/-
--data-urlencode + 参数对参数进行Percent-encoding,参数有如下形式:-
"content"参数为字符串,会对content进行encode -
"=content"参数为等号加字符串,只对content进行encode -
"name=content"参数为key = value形式,会对content进行encode. -
"@file",参数为@+文件名,会对文件内容进行encode -
"name@file",相当于 name = filecontent,对filecontent进行encode -
"=user name=content",这种形式会对user name,content都进行encode.
-
-
-
-Fmultipart/form-data形式,用法类似于-d
curl -F person=anonymous -F secret=@file.txt http://example.com/submit.cgi
-
-G或--get,在即使使用-d的情况下,还是使用get请求。
curl -d "name=annoymous" -G http://www.example.com
-H设置Header
curl -H "User-Agent:curl" -H "Cookie:BDORZ=27315;max-age=86400; domain=baidu.com" -H "Content-type:text/html" http://www.baidu.com
-
-b或者--cookie 请求头设置cookie,类似于read cookie
curl -b "Content-type:Application/json" http://example.com
curl -b @file http://example.com #从flie中读取cookie。
-
-c或者--cookie-jar保存cookie,类似于 write cookie.
#将cookie保存到cookie-jar.txt文件中
curl -c cookie-jar.txt http://example.com










网友评论