1 回答
TA贡献1828条经验 获得超6个赞
在 JavaScript 中我会这样做:
response
.replaceAll(/^(?!set-cookie).*|^set-cookie: /gmi,"")
.trim()
.replaceAll(/[\r\n]+/g, ';')
样本:
cleanCoockie = response => {
return response
.replaceAll(/^(?!set-cookie).*|^set-cookie: /gmi,"")
.trim()
.replaceAll(/[\r\n]+/g, ';')
};
$("#result").html(
cleanCoockie("HTTP/2 200 \ncontent-type: application/json; charset=utf-8\nvary: Cookie, Accept-Language, Accept-Encoding\ncontent-language: en\ndate: Wed, 08 Jul 2020 21:20:44 GMT\ncontent-encoding: gzip\nset-cookie: ds_user=usadaida521; Domain=.instagram.com; expires=Tue, 06-Oct-2020 21:20:44 GMT; HttpOnly; Max-Age=7776000; Path=/; Secure\nset-cookie: csrftoken=ev0sLTzbC4WIIk2FKvGcLLyVqgiFXD3A; Domain=.instagram.com; expires=Wed, 07-Jul-2021 21:20:44 GMT; Max-Age=31449600; Path=/; Secure\nset-cookie: rur=FTW; Domain=.instagram.com; HttpOnly; Path=/; Secure\nset-cookie: ds_user_id=35321243349; Domain=.instagram.com; expires=Tue, 06-Oct-2020 21:20:44 GMT; Max-Age=7776000; Path=/; Secure\nset-cookie: sessionid=35321243349%3AP3jlNxxuIVGoJx%3A24; Domain=.instagram.com; expires=Thu, 08-Jul-2021 21:20:44 GMT; HttpOnly; Max-Age=31536000; Path=/; Secure\ncontent-length: 685\nalt-svc: h3-29=\":443\"; ma=3600,h3-27=\":443\"; ma=3600")
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea id="result" rows="9" cols="80"></textarea>
- 1 回答
- 0 关注
- 131 浏览
添加回答
举报