使用Chrome開發(fā)者工具即Charles等抓包后可以到處.har格式的網絡請求包橘券,例如:
1输虱、打開Chrome瀏覽器
2、打開開發(fā)者工具怀跛,切換到網絡面板
3噪裕、瀏覽器訪問https://httpbin.org/get?a=1&b=2
4旧巾、在開發(fā)者工具,網絡面包點擊導出圖標,如下圖:
選擇位置并保持,得到一個httpbin.org.har的文件衍腥。
這個文件實際上是一個基于JSON格式的純文本文件,可以使用記事本等打開纳猫。例如使用VsCode打開后婆咸,顯示如下:
完整格式如下:
{
"log": {
"version": "1.2",
"creator": {
"name": "WebInspector",
"version": "537.36"
},
"pages": [
{
"startedDateTime": "2022-05-12T01:45:27.174Z",
"id": "page_1",
"title": "https://httpbin.org/get?a=1&b=2",
"pageTimings": {
"onContentLoad": 1118.679000006523,
"onLoad": 1379.2790000443347
}
}
],
"entries": [
{
"_initiator": {
"type": "other"
},
"_priority": "VeryHigh",
"_resourceType": "document",
"cache": {},
"connection": "396",
"pageref": "page_1",
"request": {
"method": "GET",
"url": "https://httpbin.org/get?a=1&b=2",
"httpVersion": "http/2.0",
"headers": [
{
"name": ":authority",
"value": "httpbin.org"
},
{
"name": ":method",
"value": "GET"
},
{
"name": ":path",
"value": "/get?a=1&b=2"
},
{
"name": ":scheme",
"value": "https"
},
{
"name": "accept",
"value": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
},
{
"name": "accept-encoding",
"value": "gzip, deflate, br"
},
{
"name": "accept-language",
"value": "zh-CN,zh;q=0.9,en;q=0.8"
},
{
"name": "cache-control",
"value": "no-cache"
},
{
"name": "dnt",
"value": "1"
},
{
"name": "pragma",
"value": "no-cache"
},
{
"name": "sec-ch-ua",
"value": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"101\", \"Google Chrome\";v=\"101\""
},
{
"name": "sec-ch-ua-mobile",
"value": "?0"
},
{
"name": "sec-ch-ua-platform",
"value": "\"macOS\""
},
{
"name": "sec-fetch-dest",
"value": "document"
},
{
"name": "sec-fetch-mode",
"value": "navigate"
},
{
"name": "sec-fetch-site",
"value": "none"
},
{
"name": "sec-fetch-user",
"value": "?1"
},
{
"name": "upgrade-insecure-requests",
"value": "1"
},
{
"name": "user-agent",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36"
}
],
"queryString": [
{
"name": "a",
"value": "1"
},
{
"name": "b",
"value": "2"
}
],
"cookies": [],
"headersSize": -1,
"bodySize": 0
},
"response": {
"status": 200,
"statusText": "",
"httpVersion": "http/2.0",
"headers": [
{
"name": "access-control-allow-credentials",
"value": "true"
},
{
"name": "access-control-allow-origin",
"value": "*"
},
{
"name": "content-length",
"value": "1052"
},
{
"name": "content-type",
"value": "application/json"
},
{
"name": "date",
"value": "Thu, 12 May 2022 01:45:12 GMT"
},
{
"name": "server",
"value": "gunicorn/19.9.0"
}
],
"cookies": [],
"content": {
"size": 1052,
"mimeType": "application/json",
"text": "{\n \"args\": {\n \"a\": \"1\", \n \"b\": \"2\"\n }, \n \"headers\": {\n \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\", \n \"Accept-Encoding\": \"gzip, deflate, br\", \n \"Accept-Language\": \"zh-CN,zh;q=0.9,en;q=0.8\", \n \"Cache-Control\": \"no-cache\", \n \"Dnt\": \"1\", \n \"Host\": \"httpbin.org\", \n \"Pragma\": \"no-cache\", \n \"Sec-Ch-Ua\": \"\\\" Not A;Brand\\\";v=\\\"99\\\", \\\"Chromium\\\";v=\\\"101\\\", \\\"Google Chrome\\\";v=\\\"101\\\"\", \n \"Sec-Ch-Ua-Mobile\": \"?0\", \n \"Sec-Ch-Ua-Platform\": \"\\\"macOS\\\"\", \n \"Sec-Fetch-Dest\": \"document\", \n \"Sec-Fetch-Mode\": \"navigate\", \n \"Sec-Fetch-Site\": \"none\", \n \"Sec-Fetch-User\": \"?1\", \n \"Upgrade-Insecure-Requests\": \"1\", \n \"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36\", \n \"X-Amzn-Trace-Id\": \"Root=1-627c66a8-2b7fa5721cd3296b14fb6362\"\n }, \n \"origin\": \"114.247.113.179\", \n \"url\": \"https://httpbin.org/get?a=1&b=2\"\n}\n"
},
"redirectURL": "",
"headersSize": -1,
"bodySize": -1,
"_transferSize": 1194,
"_error": null
},
"serverIPAddress": "44.195.242.112",
"startedDateTime": "2022-05-12T01:45:27.172Z",
"time": 1051.2589999805539,
"timings": {
"blocked": 27.15599998584017,
"dns": 0.013999999999999346,
"ssl": 462.058,
"connect": 462.686,
"send": 0.6610000000000014,
"wait": 560.4049999897666,
"receive": 0.3370000049471855,
"_blocked_queueing": 1.8709999858401716
}
},
{
"_initiator": {
"type": "other"
},
"_priority": "High",
"_resourceType": "other",
"cache": {},
"connection": "396",
"pageref": "page_1",
"request": {
"method": "GET",
"url": "https://httpbin.org/favicon.ico",
"httpVersion": "http/2.0",
"headers": [
{
"name": ":authority",
"value": "httpbin.org"
},
{
"name": ":method",
"value": "GET"
},
{
"name": ":path",
"value": "/favicon.ico"
},
{
"name": ":scheme",
"value": "https"
},
{
"name": "accept",
"value": "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"
},
{
"name": "accept-encoding",
"value": "gzip, deflate, br"
},
{
"name": "accept-language",
"value": "zh-CN,zh;q=0.9,en;q=0.8"
},
{
"name": "cache-control",
"value": "no-cache"
},
{
"name": "cookie",
"value": "_dd_s=logs=1&id=89afa2ae-542e-466c-91e3-690fda08e5c8&created=1652319928481&expire=1652320828481"
},
{
"name": "dnt",
"value": "1"
},
{
"name": "pragma",
"value": "no-cache"
},
{
"name": "referer",
"value": "https://httpbin.org/get?a=1&b=2"
},
{
"name": "sec-ch-ua",
"value": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"101\", \"Google Chrome\";v=\"101\""
},
{
"name": "sec-ch-ua-mobile",
"value": "?0"
},
{
"name": "sec-ch-ua-platform",
"value": "\"macOS\""
},
{
"name": "sec-fetch-dest",
"value": "image"
},
{
"name": "sec-fetch-mode",
"value": "no-cors"
},
{
"name": "sec-fetch-site",
"value": "same-origin"
},
{
"name": "user-agent",
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36"
}
],
"queryString": [],
"cookies": [
{
"name": "_dd_s",
"value": "logs=1&id=89afa2ae-542e-466c-91e3-690fda08e5c8&created=1652319928481&expire=1652320828481",
"path": "/",
"domain": "httpbin.org",
"expires": "2022-05-12T02:00:28.000Z",
"httpOnly": false,
"secure": false,
"sameSite": "Strict"
}
],
"headersSize": -1,
"bodySize": 0
},
"response": {
"status": 404,
"statusText": "",
"httpVersion": "http/2.0",
"headers": [
{
"name": "access-control-allow-credentials",
"value": "true"
},
{
"name": "access-control-allow-origin",
"value": "*"
},
{
"name": "content-length",
"value": "233"
},
{
"name": "content-type",
"value": "text/html"
},
{
"name": "date",
"value": "Thu, 12 May 2022 01:45:13 GMT"
},
{
"name": "server",
"value": "gunicorn/19.9.0"
}
],
"cookies": [],
"content": {
"size": 233,
"mimeType": "text/html",
"text": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n<title>404 Not Found</title>\n<h1>Not Found</h1>\n<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>\n"
},
"redirectURL": "",
"headersSize": -1,
"bodySize": -1,
"_transferSize": 369,
"_error": null
},
"serverIPAddress": "44.195.242.112",
"startedDateTime": "2022-05-12T01:45:28.562Z",
"time": 229.52200000872836,
"timings": {
"blocked": 1.5150000325813888,
"dns": -1,
"ssl": -1,
"connect": -1,
"send": 0.19500000000000006,
"wait": 227.42900002838672,
"receive": 0.38299994776025414,
"_blocked_queueing": 0.784000032581389
}
}
]
}
}
其基本格式如下:
log: 捕獲的紀錄,最外層
pages: 捕獲的頁面芜辕,每個頁面有個頁面id
entries: 捕獲的所有接口
request: 接口中包含請求信息
response:接口中的響應信息
因此我們可以使用代碼解析出其中的請求即請求數據尚骄、請求頭等進行“重放”請求。
最后:你如果是對python自動化測試侵续、web自動化倔丈、接口自動化、移動端自動化状蜗、面試經驗交流等等感興趣的測試人需五,可以 點這自行獲取…