抓包導出的har格式解析

使用Chrome開發(fā)者工具即Charles等抓包后可以到處.har格式的網絡請求包橘券,例如:

1输虱、打開Chrome瀏覽器

2、打開開發(fā)者工具怀跛,切換到網絡面板

3噪裕、瀏覽器訪問https://httpbin.org/get?a=1&b=2

4旧巾、在開發(fā)者工具,網絡面包點擊導出圖標,如下圖:

image.png

選擇位置并保持,得到一個httpbin.org.har的文件衍腥。

這個文件實際上是一個基于JSON格式的純文本文件,可以使用記事本等打開纳猫。例如使用VsCode打開后婆咸,顯示如下:

image.png

完整格式如下:

{
  "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自動化倔丈、接口自動化、移動端自動化状蜗、面試經驗交流等等感興趣的測試人需五,可以 點這自行獲取…

?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市诗舰,隨后出現的幾起案子警儒,更是在濱河造成了極大的恐慌,老刑警劉巖眶根,帶你破解...
    沈念sama閱讀 211,194評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現場離奇詭異边琉,居然都是意外死亡属百,警方通過查閱死者的電腦和手機,發(fā)現死者居然都...
    沈念sama閱讀 90,058評論 2 385
  • 文/潘曉璐 我一進店門变姨,熙熙樓的掌柜王于貴愁眉苦臉地迎上來族扰,“玉大人,你說我怎么就攤上這事定欧∮婧牵” “怎么了?”我有些...
    開封第一講書人閱讀 156,780評論 0 346
  • 文/不壞的土叔 我叫張陵砍鸠,是天一觀的道長扩氢。 經常有香客問我,道長爷辱,這世上最難降的妖魔是什么录豺? 我笑而不...
    開封第一講書人閱讀 56,388評論 1 283
  • 正文 為了忘掉前任朦肘,我火速辦了婚禮,結果婚禮上双饥,老公的妹妹穿的比我還像新娘媒抠。我一直安慰自己,他們只是感情好咏花,可當我...
    茶點故事閱讀 65,430評論 5 384
  • 文/花漫 我一把揭開白布趴生。 她就那樣靜靜地躺著,像睡著了一般昏翰。 火紅的嫁衣襯著肌膚如雪冲秽。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,764評論 1 290
  • 那天矩父,我揣著相機與錄音锉桑,去河邊找鬼。 笑死窍株,一個胖子當著我的面吹牛民轴,可吹牛的內容都是我干的。 我是一名探鬼主播球订,決...
    沈念sama閱讀 38,907評論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼后裸,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了冒滩?” 一聲冷哼從身側響起微驶,我...
    開封第一講書人閱讀 37,679評論 0 266
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎开睡,沒想到半個月后因苹,有當地人在樹林里發(fā)現了一具尸體,經...
    沈念sama閱讀 44,122評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡篇恒,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 36,459評論 2 325
  • 正文 我和宋清朗相戀三年扶檐,在試婚紗的時候發(fā)現自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片胁艰。...
    茶點故事閱讀 38,605評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡款筑,死狀恐怖,靈堂內的尸體忽然破棺而出腾么,到底是詐尸還是另有隱情奈梳,我是刑警寧澤,帶...
    沈念sama閱讀 34,270評論 4 329
  • 正文 年R本政府宣布解虱,位于F島的核電站攘须,受9級特大地震影響,放射性物質發(fā)生泄漏饭寺。R本人自食惡果不足惜阻课,卻給世界環(huán)境...
    茶點故事閱讀 39,867評論 3 312
  • 文/蒙蒙 一叫挟、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧限煞,春花似錦抹恳、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,734評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至旺上,卻和暖如春瓶蚂,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背宣吱。 一陣腳步聲響...
    開封第一講書人閱讀 31,961評論 1 265
  • 我被黑心中介騙來泰國打工窃这, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人征候。 一個月前我還...
    沈念sama閱讀 46,297評論 2 360
  • 正文 我出身青樓杭攻,卻偏偏與公主長得像,于是被迫代替她去往敵國和親疤坝。 傳聞我的和親對象是個殘疾皇子兆解,可洞房花燭夜當晚...
    茶點故事閱讀 43,472評論 2 348

推薦閱讀更多精彩內容