ios - Set cookies with NSURLSession -


Hi, I am developing an iPhone app in which I want to set a cookie after the server response and want to use it for another request. My network request looks.
  NSURL session * session = [NSURL session sharing session]; [[Session dataTaskWithURL: url completionHandler: ^ (NSData * data, NSURLResponse * response, NSError * error) {NSHTTPURLResponse * httpResp = (NSHTTPURLResponse *) response; NSLog (@ "Stats code% i", httpResp.statusCode); If (error) {[self. Delegate signinWithError: error]; } And {{self. Basic Signin Withstanding: Data]; }}] Biodata];   

But I do not know how to set cookies I know that I have to use NSHTTPCookieStorage , but I do not know how to set up and I I want to use cookies for another request. Is there anyone who knows about this? Need help. Thank you.

I tried this way

  NSURL session * session = [NSURL session sharing session]; [[Session Data Task with url: url completionHandler: ^ (NSDTA * data, NSRRSponation * response, NSERR * error) {if (error. Delegate signinWithError: error]; } Other {NSHTCPRRPPRPS * httpResp = (NSHTPRRSpons *) response; [[NSHTPKookyShare Shared HTTPCookieStories] SetsKookySpolicy: NSHTQQKeCyPolicyAlways]; NSHTTPCookie * Cookie; NSMutableDictionary * CookieProperties = [NSMutableDictionary dictionary]; NSDictionary * header = [allHeaderFields] [[NSHTTPURL response *] feedback; (NSString * key [headers allKeys]) for {NSLog (@ "% @ ..PPPP ...% @", key, [header objectForky: key]); [Cookie properties set object: [header object for: key] key: key]; } [Cookie properties set object: [[NSDate date] dateByAddingTimeInterval: 2629743] forKey: NSHTTPCookieExpires]; Cookie = [nshtpcookie cookieAuth properties: cookieproperties]; [[NSHTTPKookyShare SharePHP Cookie Storage] Set Cookie: Cookie]; [Self. Digit Signin Withstanding: Data]; }}] Biodata];   

I'm only interested in a hedder field set-cookie SSID = kgu62c0fops35n6qbf12anqlo7; Path = /

You probably only use it for, and then use Do or Single - The latter can be better for your needs.

If this does not work, you may need to set up and set up

Docs do not explain it, but the shared store can be used anyway is.

  NSURL session * session = [NSURL session sharing session]; [[Session dataTaskWithURL: url completionHandler: ^ (NSData * data, NSURLResponse * response, NSError * error) {NSHTTPURLResponse * httpResp = (NSHTTPURLResponse *) response; NSArray * cookies = [NSHttpcookie cookiesSpaceSpaceHeaderField: forURL for [all headerfiled]: [response url]]; [[NSHTTPCookieStorage Share HTTP Cookie Stost] Set Cookies: URL for Cookies: [Response URL] Main Document: Zero]; NSLog (@ "Stats code% i", httpResp.statusCode); If (error) {[self. Delegate signinWithError: error]; } And {{self. Basic Signin Withstanding: Data]; }}] Biodata];    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -