0
當我連接到測試timout的端口號時,我的應用程序凍結。 我打電話給[request setTimeoutInterval:10];
,我認爲這應該是10秒鐘。但是,該應用程序掛起。它可能與它是一個本地服務器有關嗎?iPhone [請求setTimeoutInterval:10]不工作,應用程序凍結
代碼:
// call this when program first starts
-(void) nSendMessage : (NSString *) name Password: (NSString *) password page: (NSString *) page
{
// set the url
NSString *address = @"http://localhost:1075/update";
address=[ address stringByAppendingString: page];
NSMutableURLRequest *request =
[[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:address]];
// post or get
[request setHTTPMethod:@"POST"];
// data to send
NSString *postString = @"username=iusername&password=ipassword";
NSString *sendString=[postString stringByReplacingOccurrencesOfString:@"iusername" withString: name];
sendString=[sendString stringByReplacingOccurrencesOfString:@"ipassword" withString: password];
[request setValue:[NSString
stringWithFormat:@"%d", [sendString length]]
forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[sendString
dataUsingEncoding:NSUTF8StringEncoding]];
[request setTimeoutInterval:10];
[[NSURLConnection alloc]
initWithRequest:request delegate:self];
//
//THE PROGRAM FREEZES HERE
//
NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *response = [[NSString alloc] initWithData:urlData encoding:NSASCIIStringEncoding];
// Phrase repl
[self nUpdateDisplay:response];
}