iphone - Problem with NSHTTPCookie -
i want make login application. first screen login form 2 text fields , 1 button. when pres button invoke 1 method invoke method:
- (int)login { // add data post request nshttpurlresponse * response; nsstring *myrequeststring = [[nsstring alloc] initwithformat:@"userdata='%@'&passdata='%@'", username.text, password.text]; nserror * error; nsdata *myrequestdata = [nsdata datawithbytes: [myrequeststring utf8string] length: [myrequeststring length]]; nsmutableurlrequest *request; request = [[[nsmutableurlrequest alloc] initwithurl:[nsurl urlwithstring:@"http://server.com/login.php"] cachepolicy:nsurlrequestreloadignoringcachedata timeoutinterval:60] autorelease]; [request sethttpmethod: @"post"]; [request sethttpbody: myrequestdata]; [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; nsdata * data = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; nsarray * = [nshttpcookie cookieswithresponseheaderfields:[response allheaderfields] forurl:[nsurl urlwithstring:@"http://server.com/login.php"]]; //int cid; (nshttpcookie *cookie in all) { nslog(@"name: %@ : value: %@", cookie.name, cookie.value); // cid = (int)cookie.value; } // nslog(@"id: %d",cid); [myrequeststring release]; [request release]; return 1; }
when pres button program crash , next row:
nsarray * = [nshttpcookie cookieswithresponseheaderfields:[response allheaderfields] forurl:[nsurl urlwithstring:@"http://sms.britecs.com/login.php"]];
i have thread1: program received signal: "exc_bad_access"
don't know how fix it.
i have 1 more question. how can use cookies in next screen?
thanks
with [request release];
releasing autoreleased object. don't that, it'll released next run loop cycle autorelease pool. remove autorelease @ end of initialization , fine, else remove release statement.
here creating it:
request = [[[nsmutableurlrequest alloc] initwithurl:[nsurl urlwithstring:@"http://server.com/login.php"] cachepolicy:nsurlrequestreloadignoringcachedata timeoutinterval:60] autorelease]; // <---
Comments
Post a Comment