2010-05-31 88 views
1

當我執行函數的最後一行(webData)時,我得到了一個EXC_BAD_ACCESSEXC_BAD_ACCESS NSUrlConnection

-(void)requestSoap{ 
NSString *requestUrl = @"http://www.website.com/webservice.php"; 
NSString *soapMessage = @"the soap message"; 
//website and soapmessage are valid in original code. 

NSError **error; 
NSURLResponse *response; 

//Convert parameter string to url 
NSURL *url = [NSURL URLWithString:requestUrl]; 
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10]; 

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; 

//Create an XML message for webservice 
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
[theRequest setHTTPMethod:@"POST"]; 
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

NSData *webData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:error]; 
} 

我試圖不發佈一件事情,因爲我在網上讀到的是它幾乎總是一個記憶的東西。

當我調試代碼(NSZombieEnabled = YES)這是我得到:

[Session started at 2010-05-31 15:56:13 +0200.] 
GNU gdb 6.3.50-20050815 (Apple version gdb-1461.2) (Fri Mar 5 04:43:10 UTC 2010) 
Copyright 2004 Free Software Foundation, Inc. 
GDB is free software, covered by the GNU General Public License, and you are 
welcome to change it and/or distribute copies of it under certain conditions. 
Type "show copying" to see the conditions. 
There is absolutely no warranty for GDB. Type "show warranty" for details. 
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all 
Attaching to process 19856. 
test(19856) malloc: recording malloc stacks to disk using standard recorder 
test(19856) malloc: enabling scribbling to detect mods to free blocks 
test(19856) malloc: process 19832 no longer exists, stack logs deleted from /tmp/stack-logs.19832.test.w9Ek4L.index 
test(19856) malloc: stack logs being written into /tmp/stack-logs.19856.test.URRpQF.index 
Program received signal: 「EXC_BAD_ACCESS」. 

是否有人有線索?

+1

的 「NSError **錯誤」 似乎好像有一個*太多。 另外,當將錯誤傳遞給「發送同步」時,將其作爲存儲錯誤地址的&錯誤。 – RickiG 2010-05-31 14:09:34

+0

使用一系列斷點,您可以確切確定導致EXEC_的哪條線。 – 2010-05-31 14:11:26

+0

>他「NSError **錯誤」好像有一個*太多。另外,將錯誤傳遞給「發送同步」時,將其作爲存儲錯誤地址的錯誤。 只是偉大的RickiG,我只是沒有看到它。什麼blooper。 非常感謝! – Lars 2010-05-31 14:13:38

回答

1

error變量的定義存在錯誤。您應該使用

NSError *error; 

,而不是

NSError **error; // There is a '*' too much here 

然後,當您將它傳遞給sendSynchronousRequest:returningResponse:error:你應該它的地址使用&error傳:

[NSURLConnection sendSynchronousRequest:theRequest 
         returningResponse:&response 
            error:&error];