Use curl in Bat to request the post interface (application/x-www-form-urlencoded) and carry the request header and request parameters

Scenes

It is necessary to test the traversability and return data of an interface online.

If it is a get request, it can be verified directly in the browser. If it is a post request and you don’t want to install third-party tools such as postman, you can use

Create a new bat script file to test the interface.

Note:

Blog:
Overbearing rogue temperament blog_CSDN Blog-C#, Architecture Road, Blogger in SpringBoot

accomplish

1. For example, the interface to be tested is described as follows

 

The request type of the interface here is post, and the request data type is application/x-www-form-urlencoded, and two parameters and a request header need to be passed

2. Create a new bat script and modify the content as follows


curl http://127.0.0.1:8080/test ^
-X POST ^
-H "Content-Type: application/x-www-form-urlencoded" ^
-H "Authorization: Basic sdfsdsdgdfgdfgdfgfdg" ^
-d "username=admin&password=dfgdffdghfhfghfgh"
pause

Notice:

Among them, ^ stands for command line break, here for more intuitive, if it is displayed in one line, it can be removed.

Cur is followed by the interface address.

-X POST indicates that the request method is POST.

-H means add request header.

-d stands for adding request parameters.

running result

 

Guess you like

Origin blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/131674234