Simple to use curl in development

linux curl commands can be sent on a http request. Of course, Postman is a good management tool interface call, but the call under another linux server API is available in the scene, none other than the non-curl command to verify a linux server.

The following Xiaoming mainly to tell you about common curl command scenario, we can accumulate some knowledge of operation and maintenance, and application development in their daily work.

Open a Web site

curl www.mynamecoder.com

POST request sent

curl -d "userName=xiaoming&password=coder1024" http://www.mynamecoder.com/login

Parameter Description

-d:指定传入的参数

Used -dafter parameters, HTTP requests will automatically add request header Content-Type : application/x-www-form-urlencoded. And automatically converted POST method request.

Send GET request

curl -d "title=curl" http://www.mynamecoder.com/search

Parameter Description

-G:表示get请求,缺省为post请求

POST request JSON format

$ curl -d '{"userName": "xiaoming", "password": "123456"}' -H 'Content-Type: application/json' https://www.mynamecoder.com/login

Parameter Description

-H:指明 HTTP 请求头

upload files

curl -F '[email protected]' https://mynamecoder.com/upload

Parameter Description

The above command will add HTTP request header Content-Type: multipart/form-data, then the file photo.pngas a filefield to upload.

-FParameters can be specified MIME type.

curl -F '[email protected];type=image/png' https://mynamecoder.com/upload

The above command specifies the MIME type image/png, or MIME type will default to curl application/octet-stream.

-FParameters can also specify the file name.

$ curl -F '[email protected];filename=me.png' https://mynamecoder.com/upload

The above command, the original file is named photo.png, but the server receives a file named me.png.

Xiao Ming curl command currently used on these, we need can be directly used to use!

Conclusion

Recently Xiao Ming is a bit lazy, and soon the end of 2019, and try to ensure that by 2020 a week to share their daily development!
Welcome attention to micro-channel public number "programmer Xiao Ming", for more resources.
Programmer Xiao Ming

Guess you like

Origin www.cnblogs.com/coderxx/p/12123997.html