Rob Bonner
Rob Bonner

Reputation: 9426

Remove a cookie from NSURLRequest

I need to expire a specific cookie when making a NSURLRequest, but don't see any way to expire a specific cookie. Is this possible?

Upvotes: 1

Views: 1442

Answers (1)

Kyle
Kyle

Reputation: 1595

Cookies are returned as part of a HTTP response (using the Set-Cookie: header, see here) and they are maintained by your browser (not the server). It is therefore up to whatever is handling the HTTP responses (in this case, your Objective-C code) to store cookies and pass them to the server with each request.

Therefore it doesn't make sense for you to try to expire cookies in an NSURLRequest because the server you are making a request to doesn't even know about the cookies unless you send them along in the Cookie: header of the request.

If you are using NSURLRequest, you are going to have to parse cookies from Set-Cookie: headers in the response, store them, and then send them along with subsequent requests. Then you can simply choose not to send along a cookie if you want it expired.

Upvotes: 1

Related Questions