Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i stop ios from automatically adding cookie to my NSMutableURLRequest

Tags:

ios

cookies

i am hitting a url with the following code:

NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequestHttp returningResponse:&theResponse error:&theError];

and i have theRequestHttp initialized here:

NSMutableURLRequest *theRequestHttp = [[NSMutableURLRequest alloc] initWithURL:url];

no where do i have the cookie being added to the urlrequest... in fact, i have the following set:

[theRequestHttp addValue:nil forHTTPHeaderField:@"Cookie"];

i also tried with

[theRequestHttp setValue:nil forHTTPHeaderField:@"Cookie"];

is there any way to NOT add the Cookie?

like image 219
s5v Avatar asked Dec 24 '22 15:12

s5v


2 Answers

[request setHTTPShouldHandleCookies:NO];
like image 191
Pablo A. Avatar answered Dec 31 '22 13:12

Pablo A.


I don't know if you can disable automatic addition of cookies but you can delete cookies anytime you want using the following code

NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];

for (NSHTTPCookie *cookie in storage.cookies) {

      [storage deleteCookie:cookie];
}
like image 44
Fawad Masud Avatar answered Dec 31 '22 12:12

Fawad Masud