一.moco框架mock接口信息
[
{
"description": "这是一个能返回cookies信息的get请求",
"request": {
"uri": "/getCookies",
"method": "get"
},
"response": {
"cookies": {
"login": "true"
},
"text": "成功获取到cookies信息啦"
}
},
{
"description": "这是一个携带cookie的get请求",
"request": {
"uri": "/get/with/cookie",
"method": "get",
"cookies": {
"login": "true"
}
},
"response": {
"text": "这是一个需要携带cookie的才能访问的get请求"
}
}
]
二.application.properties配置文件信息
test.url=http://localhost:8080
getCookies.uri=/getCookies
test.get.with.cookies=/get/with/cookie
三.编写testNG测试方法
package com.course.httpclient.cookies;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.CookieStore;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
impor