У меня здесь довольно необычная проблема. Код ниже работает нормально, и данные отправляются в исходный файл, но ни один из триггеров NSURLConnection ничего не возвращает. Единственные элементы, которые регистрируются, находятся в функции отправки запроса. Любые идеи?NSURLConnection Не возвращающие данные
// code starts above here
NSData *myRequestData = [ NSData dataWithBytes: [ requestString UTF8String ] length: [ requestString length ] ];
NSURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlPrefix]];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: myRequestData];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
NSURLResponse *resp = nil;
NSError *err = nil;
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse: &resp error: &err];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
if (!theConnection)
{
NSLog(@"Failed to submit request");
}
if(theConnection)
{
NSMutableData* receivedData=[[NSMutableData data] retain];
NSLog(@"Created connection.");
NSLog(@"--------- Request submitted ---------");
NSLog(@"receivedData: %@", receivedData);
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"Received response: %@", response);
NSLog(@"Received response, connection retain count is %d",[connection retainCount]);
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(@"Connection received data, retain count: %d", [connection retainCount]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"finished connection retain count: %d", [connection retainCount]);
}
Что можно сказать о соединении: willSendRequest: redirectResponse :? Кроме того, вы всегда должны использовать -connection: didFailWithError :. – Costique
К сожалению, есть соединение: функция didFailWithError, но в моем коде ниже, но – Matt