나는이 질문 자습서 다음되었습니다왜 내 대리자 메서드가 호출되지 않습니까?
- fetching data with get post methods
- sending http get and post from cocoa
- nsurlconnection basics for beginners
- sending an http post request on ios
- how to hanlde multiple delegates
을하지만 난 여전히 뭔가를 놓친 거지. 내 위임 방법
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
는 항상라는 약간의 시간이 걸리고 나는 때문에 인터넷 속도의의를 생각하지만, 방법
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data
결코 불려갑니다됩니다. 내가 뭘 놓치고 있니? 도와주세요.
내 코드 :
-(void)loadDataBase{
NSString *post = [NSString stringWithFormat:@"advnr=123"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://thewebsite.abc/interface.php"]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
//return @"";
}
#pragma mark -
#pragma mark NSURLConnection delegates
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data {
NSLog(@"Success"); // never gets executed
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"didFinished");
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"FAILED");
}
이 대리자 메서드 경우에만 웹 서비스 반환 데이터, you'r 요청 데이터를 반환 기타를 게시 있다고 확신 할 때 호출 200 HTTP 헤더보다? –
네, HTML 테스트 폼으로 테스트 할 때 항상 필요한 데이터를 얻습니다. –