Simulate POST/GET requests with curl commands

The curl command is a file transfer tool that works from the command line using URL rules. It supports uploading and downloading of files. curl supports many protocols including HTTP, HTTPS, ftp, etc. It also supports POST, cookies, authentication, downloading partial files from a specified offset, user agent string, speed limit, file size, progress bar and other features.

In the process of developing and testing web background programs, it is often necessary to send urls for testing. Using curl can easily simulate url commands that meet the requirements.

Suppose the target url is: 127.0.0.1:8080/login

Send a GET request with curl: curl protocol://address:port/url?args

[plain]  view plain copy  
  1. curl http://127.0.0.1:8080/login?admin&passwd=12345678  
Send a POST request with curl: curl -d "args" protocol://address:port/url

[plain]  view plain copy  
  1. curl -d "user=admin&passwd=12345678" http://127.0.0.1:8080/login  
In this method, the parameters are directly in the header. If you need to specify the output to a file, you can operate through redirection.
curl -H "Content-Type:application/json" -X POST -d 'json data' URL

[plain]  view plain copy  
  1. curl -H "Content-Type:application/json" -X POST -d '{"user": "admin", "passwd":"12345678"}' http://127.0.0.1:8000/login  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324478277&siteId=291194637