0
저는 iPhone 개발 세계에 새로운 사람이고 HTTP 메소드 POST를 사용하여 웹 서비스를 호출하려고합니다.NSMutableUrlRequest의 didReceiveData가 결코 트리거되지 않았습니다
NSMutableUrlRequest를 사용하고 있습니다. 내 문제는 DidReceiveData 대리자가 호출되지 않으며 NSUrlConnection이 null을 반환하지 않는다는 것입니다. 내가하시기 바랍니다 중요한 무언가를 잊어 버린 경우
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data
{
NSLog(@"didReceiveData");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"didFinishLoading");
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError");
}
- (void) HttpRequest
{
NSLog(@"Calling HttpRequest");
NSString *parameters = @"placeName=Restau";
NSData *postData = [parameters dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *webServiceUrl = [NSURL URLWithString:@"http://api.malves.fr/API.asmx/EngineSearchPlaceService"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:webServiceUrl];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"keep-live" forHTTPHeaderField:@"Connection"];
[request setValue:@"300" forHTTPHeaderField:@"Keep-Alive"];
[request setHTTPBody:postData];
NSURLConnection *connectionResponse = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (!connectionResponse)
{
NSLog(@"Failed to submit request");
}
else
{
NSLog(@"Request submitted");
}
NSLog(@"Sleeping... ZZZZzzzzzz");
[NSThread sleepForTimeInterval:10];
NSLog(@"Sleep done");
}
누군가가 말해 줄 수 : 여기
내 코드? 고마워.
내 웹 서비스는 비누 요청과 간단한 게시물 요청을 모두 지원합니다. –