实战地址:http://47.107.178.45/phpwind/index.php?m=bbs
var token = responseBody.match(new RegExp(/name="csrf_token" value="(.+?)"/))[1];
pm.globals.set("token",token);
{
"info": {
"_postman_id": "5f78663c-d674-4b33-845d-0baf7959b40c",
"name": "项目实战",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "论坛注册",
"event": [
{
"listen": "test",
"script": {
"id": "ae36924c-508a-4658-ab05-3f5e3dc2bb69",
"exec": [
"var username='yangchaoyi';",
"pm.globals.set(\"username\",username);",
"pm.globals.set(\"pwd\",\"123456\");",
"pm.globals.set(\"email\",\"[email protected]\");"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "username",
"value": "{{username}}",
"type": "text"
},
{
"key": "repassword",
"value": "{{pwd}}",
"type": "text"
},
{
"key": "password",
"value": "{{pwd}}",
"type": "text"
},
{
"key": "email",
"value": "{{email}}",
"type": "text"
},
{
"key": "csrf_token",
"value": "{{token}}",
"type": "text"
}
]
},
"url": {
"raw": "http://47.107.178.45/phpwind/index.php?m=u&c=register&a=dorun",
"protocol": "http",
"host": [
"47",
"107",
"178",
"45"
],
"path": [
"phpwind",
"index.php"
],
"query": [
{
"key": "m",
"value": "u"
},
{
"key": "c",
"value": "register"
},
{
"key": "a",
"value": "dorun"
}
]
},
"description": "论坛注册"
},
"response": []
},
{
"name": "获取token",
"event": [
{
"listen": "test",
"script": {
"id": "b8f8cfca-2a2a-43eb-b2f4-f877dcbf5a13",
"exec": [
"//1、获取网站token",
"// var tmp = pm.response.text();",
"// var token = tmp.match(new RegExp(/name=\"csrf_token\" value=\"(.+?)\"/))[1];",
"// pm.globals.set(\"token\",token);",
"// console.log(pm.globals.get(\"token\"));",
"",
" var token = responseBody.match(new RegExp(/name=\"csrf_token\" value=\"(.+?)\"/))[1];",
" pm.globals.set(\"token\",token);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://47.107.178.45/phpwind/index.php?m=u&c=register",
"protocol": "http",
"host": [
"47",
"107",
"178",
"45"
],
"path": [
"phpwind",
"index.php"
],
"query": [
{
"key": "m",
"value": "u"
},
{
"key": "c",
"value": "register"
}
]
}
},
"response": []
},
{
"name": "登录论坛",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "username",
"value": "{{username}}",
"type": "text"
},
{
"key": "password",
"value": "{{pwd}}",
"type": "text"
},
{
"key": "backurl",
"value": "http://47.107.178.45/phpwind/read.php?tid=66152&fid=64",
"type": "text"
},
{
"key": "invite",
"value": "",
"type": "text"
},
{
"key": "csrf_token",
"value": "{{token}}",
"type": "text"
}
]
},
"url": {
"raw": "http://47.107.178.45/phpwind/index.php?m=u&c=login&a=dorun",
"protocol": "http",
"host": [
"47",
"107",
"178",
"45"
],
"path": [
"phpwind",
"index.php"
],
"query": [
{
"key": "m",
"value": "u"
},
{
"key": "c",
"value": "login"
},
{
"key": "a",
"value": "dorun"
}
]
}
},
"response": []
},
{
"name": "发帖",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "atc_title",
"value": "yangchaoyi",
"type": "text"
},
{
"key": "atc_content",
"value": "admin888",
"type": "text"
},
{
"key": "pid",
"value": "",
"type": "text"
},
{
"key": "tid",
"value": "",
"type": "text"
},
{
"key": "special",
"value": "default",
"type": "text"
},
{
"key": "reply_notice",
"value": "1",
"type": "text"
},
{
"key": "csrf_token",
"value": "{{token}}",
"type": "text"
}
]
},
"url": {
"raw": "http://47.107.178.45/phpwind/index.php?c=post&a=doadd&_json=1&fid=73",
"protocol": "http",
"host": [
"47",
"107",
"178",
"45"
],
"path": [
"phpwind",
"index.php"
],
"query": [
{
"key": "c",
"value": "post"
},
{
"key": "a",
"value": "doadd"
},
{
"key": "_json",
"value": "1"
},
{
"key": "fid",
"value": "73"
}
]
}
},
"response": []
}
],
"protocolProfileBehavior": {}
}
今天老师讲授的时候,发现这个网址不仅需要验证token还要验证status,所以上述方法是有bug的,但是总体方法是没问题的,后续待更新ing
学如逆水行舟,不进则退