为什么nsurlconnection启动缓慢

时间:2011-08-08 13:22:11

标签: cocoa nsurlconnection

我创建一个NSURLConnection并调用我的url(这是我macbook上的本地apache)。它调用的php文件会立即返回'';这需要花费NSURLConnection 3-5秒。如果我通过Safari访问相同的URL,它应该是即时的。任何想法NSURLConnection开始这么慢的想法?

/* POST DATA */
self.postData = [@"" dataUsingEncoding:NSUTF8StringEncoding];//not data to send


/* POST REQUEST */
self.request = [[NSMutableURLRequest alloc] init];
[_request release];
[_request setURL:[[self class] URL]];
[_request setHTTPMethod:@"POST"];
[_request setValue:@"gzip,deflate" forHTTPHeaderField:@"Accept-Encoding"];  
[_request setValue:@"UTF-8" forHTTPHeaderField:@"Accept-Charset"];
[_request setValue:[NSString stringWithFormat:@"%lu", [_postData length]] forHTTPHeaderField:@"Content-Length"];
[_request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", [self boundry]] forHTTPHeaderField:@"Content-Type"];
[_request setValue:@"form-data" forHTTPHeaderField:@"Content-Disposition"];
[_request setHTTPBody: _postData];


NSDate *date = [NSDate date];
self.responseData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&_response error:&_error];//get the data
NSLog(@"%@ took %f", date, [date timeIntervalSinceNow]);

0 个答案:

没有答案