Installation of windows
Net official download link: https://curl.haxx.se/download.html
Installation: Download the zip file, unzip, add environment variables can be used
(linux release comes with general)
windows under Chinese garbled problem solving
windows support Chinese display: Using curl Console garbage problem under windows
use
GET
curl -b "cookie.txt" url
注释:
-b "cookie.txt": 从这个文件中读取cookie
POST
curl -b "cookie.txt" -H "Content-Type:application/json" -H "CSRF:abc" -d "{..}" url
注释:
-H param: 设置请求头
-H "Content-Type:application/json": 设置请求头Content-Type,以json格式发送
-H "CSRF:abc"": 设置请求头,发送CSRF这个参数
-d "{}":-d后面跟着的为需要发送的数据
Note:
. A -X POST
may be omitted, curl post command is determined automatically
b json format, if. {}
By double quotes "
, need to escape to \"
c when authentication of its interface, found that such a post request transmitted at windows. read cookie from the file when will the validation fails, we need to add yourself -H "cookie='12312'
to take effect, the reason temporarily not available
PUT/DELETE
curl -b "cookie.txt" -X PUT/DELETE -d "..." url
注释:
-X PUT/DELETE: 表示发送的是PUT/DELETE请求
upload files
curl -b "cookie.txt" -F "filename=@file" url
注释:
-F "":将会以multipart/form-data发送POST数据;如果是发送文件的话,需要在参数前面加@
Note:
. A note file name or file path is correct, such as the file name contains spaces and the like, need to pay attention, or may report "failed creating formpost data"
this error (of course this mistake more than this reason)
download file
curl -b "cookie.txt" -o filename url
curl -b "cookie.txt" -O url
注释:
-o 文件名 文件路径:将对应路径的文件以该文件名下载下来
-O:使用URL中默认的文件名保存到本地
Note
a. There are other ways like a breakpoint download, free to Baidu
Note
In use -c
, -b
read and write cookie time, pay attention to the current operation if the user has permission to read and write files, or the method might fail
Section Parameter Description
parameter | Explanation |
---|---|
-c file | The cookie file is written to this file (file is the file path) |
-b file | cookie file will be read from the file |
-X POST/PUT/DELETE | Use POST / PUT / DELETE method |
-H param | Parameter setting request header |
-d "" | Data needs to be sent to the backend |
-k | When sending https request is not authenticated (when using https request error may try added -k) |
-v | See the detailed information in the request header |
-i | For more information see the return header |
-o filename url | The corresponding path of the file downloaded to the file name |
-The url | Save a URL in the default file name to the local |
-F "key=value" | will be sent to curl multipart form-data manner / POST request data is transmitted in the form of key = value of If is a file, it is necessary in key = value @ (@ plus sign) |
Author: H_DaYan
link: https: //www.jianshu.com/p/3aecc761fb9e
Source: Jane book
Jane book copyright reserved by the authors, are reproduced in any form, please contact the author to obtain authorization and indicate the source.