views:

18

answers:

1

I am having problems storing a cookie value as a string for an iPhone project. Currently, I am retrieving the value of the cookies this way:

NSString *somevalue;

for (NSHTTPCookie *cookie in cookies)
{
    NSLog(@"Name: %@ : Value: %@, Expires: %@", cookie.name, cookie.value, cookie.expiresDate);
    somevalue = cookie.value;
}

Now, in theory this SHOULD store cookie.value as string 'somevalue'. I can do an NSLog of 'somevalue' and it retrieves the correct value.

However, when I pass this through to:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:fullUrl]];
[request setPostValue:someValue forKey:@"profile_id"];
[request setPostValue:@"1" forKey:@"start"];
[request setPostValue:@"10" forKey:@"end"];

and then check the response, it is passing in the entire cookie (this is what it looks like):

a%3A5%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%221fcd876dc0240ac4a59f3630b8f630fe%22%3Bs%3A10%3A%22ip_address%22%3Bs%3A7%3A%220.0.0.0%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A50%3A%22Doubletake+1.0+%28iPhone+Simulator%3B+iPhone+OS+3.1.3%3B%22%3Bs%3A13%3A%22last_activity%22%3Bs%3A10%3A%221276270293%22%3Bs%3A5%3A%22email%22%3Bs%3A18%3A%22tim%40domain.com%22%3B%7D5f9c567d5832013183d511dba8910cf3

Is the value actually getting stored? Why is this happening?

A: 

If you want to keep an object around past the current method invocation (or often just past the lifetime of its owner), you need to claim ownership of it with retain. See the memory management rules for a full explanation.

Chuck
Chuck, I hear what you are saying, but when I do an:NSLog(@"Name: %@", cookie.name);And then store the value of cookie.name into a String, they come out as two totally different values (The NSLog is '48', which is a stored variable, and the other variable displays the entire cookie)
squeezemylime