我有一个看起来像这样的 cookie:{"SSOsess":"300|c6dc6d60ebebf0891004353352f24b77","RTBk":"300|451706000c67a37dfe5bebe0b5d26278","ph02RPNCiscoASA":"application.api.randwebsite.com","ph03RPNCiscoASA":"application.client.randwebsite.com"}是否有任何库可以帮助我将字符串格式化为以下内容:'SSOsess=300|c6dc6d60ebebf0891004353352f24b77; RTBk=300|451706000c67a37dfe5bebe0b5d26278; ph02RPNCiscoASA=application.api.randwebsite.com; ph03RPNCiscoASA=application.client.randwebsite.com'我一直在查看set-cookie-parser但看起来它不包含任何有用的功能。
1 回答
小唯快跑啊
TA贡献1863条经验 获得超2个赞
尝试这个。
let cookie = JSON.stringify({"SSOsess":"300|c6dc6d60ebebf0891004353352f24b77","RTBk":"300|451706000c67a37dfe5bebe0b5d26278","ph02RPNCiscoASA":"application.api.randwebsite.com","ph03RPNCiscoASA":"application.client.randwebsite.com"})
var output = cookie.split(":").join("=").split(',').join("; ")
output = "'"+output.substring(1,output.length-1).replace(/"/g, "")+"'"
console.log(output)
//输出
'SSOsess=300|c6dc6d60ebebf0891004353352f24b77; RTBk=300|451706000c67a37dfe5bebe0b5d26278; ph02RPNCiscoASA=application.api.randwebsite.com; ph03RPNCiscoASA=application.client.randwebsite.com'
添加回答
举报
0/150
提交
取消