前言
通过IDEA发送HTTP请求,实现后段API接口测试
创建一个HTTP客户端
使用临时的http文件作为HTTP客户端
创建http文件
发送HTTP请求
发送GET请求
1 2
| GET http://localhost:80/api/item?id=99 Accept: application/json
|
发送POST请求
请求体传递JSON格式字符串
1 2 3 4
| POST http://localhost:80/api/item Content-Type: application/json
{}
|
请求体传递键值对字符串
1 2 3 4 5
| POST http://localhost:80/api/item Content-Type: application/x-www-form-urlencoded
id = 99 & content = new-element
|
请求体传递文本表单
1 2 3 4 5 6 7 8
| POST http://localhost:80/api/item Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary Content-Disposition: form-data; name="field-name"
field-value --WebAppBoundary--
|
请求体传递文件
1 2 3 4 5 6 7 8
| POST http://localhost:80/api/item Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary Content-Disposition: form-data; name="field-name"; filename="file.txt"
< ./relative/path/to/local_file.txt --WebAppBoundary--
|
完成
参考文献
CSDN——春花秋时知多少