开发者

why is nsurlconnection slow to start

开发者 https://www.devze.com 2023-03-26 10:50 出处:网络
I create an NSURLConnection and make a call to my url (which is to the local apache on my macbook). The php file it calls immediately returns \'\';It\'s taking the NSURLConnection 3-5 seconds. If I ac

I create an NSURLConnection and make a call to my url (which is to the local apache on my macbook). The php file it calls immediately returns ''; It's taking the NSURLConnection 3-5 seconds. If I access the same url through Safari, it's instant, as it should be. Any ideas why NSURLConnection starting so slow?

/* 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"];
开发者_Python百科[_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

精彩评论

暂无评论...
验证码 换一张
取 消