Link to home
Start Free TrialLog in
Avatar of singh101
singh101

asked on

difference between response.addCookie and response.setHeader

You can also choose to add cookies via response.setHeader(""Set-Cookie"....)
Why would you want to add a cookie using response.setHeader over response.addCookie? Are there any important differences of doing one over the other?

Thanks In advance
Avatar of sandeshj
sandeshj
Flag of India image

setHeader method of response object is used to create an HTTP Header with the name and value given as string.
Eg:
response.setHeader("Content_Type","text/html");

addCookie() method of response object is used to add the specified cookie to the response.
Eg:
response.addCookie(Cookie yourSystem);

Both are different. You can't set a cookie using setHeader. Its for passing plain Name-Value Pairs in the Header of the response.
Avatar of singh101
singh101

ASKER

I am under the assumption you can set a cookie using response.setHeader("Set-Cookie.....)
ASKER CERTIFIED SOLUTION
Avatar of sandeshj
sandeshj
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> The main difference is that a cookie has the ability to be persistent on the client machine

Thats incorrect btw, theres no difference