I'm seeing a crash that happens 10 or 20 seconds after a POST request I make has finished (didReceiveResponse
, didReceiveData
and connectionDidFinishLoading
all fire well before the crash happens).
This is the code I'm using to make the request:
NSURL* url = [[NSURL alloc] initWithString:urlString];
[urlString release];
NSData* requestData = [jsonData dataUsingEncoding:NSUTF8StringEncoding];
NSString* requestDataLengthString = [[NSString alloc] initWithFormat:@"%d", [requestData length]];
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:requestData];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:requestDataLengthString forHTTPHeaderField:@"Content-Length"];
[request setTimeoutInterval:30.0];
[url release];
[requestData release];
[requestDataLengthString release];
m_URLConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[request release];
What's very odd about this crash is this: if I do not call setHTTPBody with my NSData
object, setValue:@"application/json"
for Content-Type
and setValue:requestDataLengthString
for Content-Length
, the crash does not happen. I'm completely perplexed as to what is happening. As far as I can tell, the crash is directly related to sending an NSData
object with my request. When it does crash, the top elements in the call stack for the crash (EXEC_BAD_ACCESS
) are the following:
objc_msgSend
CFRelease
HTTPMessage::~HTTPMessage
_CFRelease
HTTPWriteFilter::~HTTPWriteFilter
Can anyone think of something I might be doing wrong? I'm completely at a loss for what I'm doing wrong, how to fix it, or how to work around it. Is there a better way to POST data than the way I'm doing?