POST请求分类:
1、根据是否修改代码,分为两种方式:
- 一种是在UI界面添加后自动生成脚本,一种是直接在脚本中添加
2、根据请求参数的不同,主要可以分为两种:
- param为key value格式
- body为json格式
一、通过UI方式发送POST请求–key/value参数
- 通过 UI 设置:脚本 -> 新建脚本 -> 显示高级配置
- 当选择了请求方法为POST后,在高级配置中默认会在headers中显示Content-Type为x-www-form-urlencoded,同时,添加key/value格式的params:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/666c66ad877654bbd69573402bfb07ff.png)
生成代码如下(由于篇幅限制,去掉import部分):
@RunWith(GrinderRunner)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class TestRunner {
public static GTest test
public static HTTPRequest request
public static NVPair[] headers = []
public static NVPair[] params = []
public static Cookie[] cookies = []
@BeforeProcess
public static void beforeProcess() {
HTTPPluginControl.getConnectionDefaults().timeout = 6000
test = new GTest(1, "www.baidu.com")
request = new HTTPRequest()
List<NVPair> headerList = new ArrayList<NVPair>()
headerList.add(new NVPair("Content-Type", "application/x-www-form-urlencoded"))
headerList.add(new NVPair("Connection", "keep-alive"))
headers =<