How to parse a cookie string

后端 未结 9 1909
眼角桃花
眼角桃花 2020-12-08 04:47

I would like to take a Cookie string (as it might be returned in a Set-Cookie header) and be able to easily modify parts of it, specifically the expiration date.

I s

9条回答
  •  盖世英雄少女心
    2020-12-08 05:12

    With a regular expression like :

    ([^=]+)=([^\;]+);\s?
    

    you can parse a cookie like this :

    .COOKIEAUTH=5DEF0BF530F749AD46F652BDF31C372526A42FEB9D40162167CB39C4D43FC8AF1C4B6DF0C24ECB1945DFF7952C70FDA1E4AF12C1803F9D089E78348C4B41802279897807F85905D6B6D2D42896BA2A267E9F564814631B4B31EE41A483C886B14B5A1E76FD264FB230E87877CB9A4A2A7BDB0B0101BC2C1AF3A029CC54EE4FBC; 
    expires=Sat, 30-Jul-2011 01:22:34 GMT; 
    path=/; HttpOnly
    

    in a few lines of code.

提交回复
热议问题