JianFang
JianFang

Reputation: 31

how to parse raw cookie

How can I parse the raw cookie string.

It must return the javax.servlet.http.Cookie object.

The raw cookie like this:

Set-Cookie: BAIDUID=66AA214F9A534411A339CE5E60D36E28:FG=1; expires=Sun, 05-Aug-42 06:41:06 GMT; path=/; domain=.baidu.com

Upvotes: 1

Views: 2372

Answers (1)

Zasz
Zasz

Reputation: 12538

I don't understand what is the difficulty you face - What have you tried ?

  • String[] pairs = String.split(";") will give you an array of name-value pairs.
  • On each name-value pair, pair.subString(0, pair.indexOf(':') + 1) will give you the name
  • pair.subString(pair.indexOf(':') + 1, pair.length - (pair.indexOf(':') + 1)) will give you the value
  • pull out pair.indexOf(':') into a variable and reuse

Upvotes: 1

Related Questions