이 iPhone POST 요청이 내 iPhone 앱에서 작동하지 않는 이유가 궁금합니다.HTTP POST 요청이 작동하지 않고 대리자 메서드가 호출되지 않습니다.
URL이 정확하고 보내는 변수가 올바른지 알고 있지만 어떤 이유로 인해 .aspx
페이지에서 요청을받지 못했습니다.
편집 :
나는 자신의 위임 방법과, 자신의 클래스에 코드를 리팩토링. 그러나 대리자 메서드는 호출되지 않습니다.
클래스는 다음과 같이 호출됩니다
URLCallClass *reporter=[[[URLCallClass alloc] init]autorelease];
[reporter sendoview:@"http://mysite/page.aspx" params:httpBodyString];
이 실제 클래스 자체입니다 : didFailWithError : 대리인의
-(void)sendview:(NSString *)server params:(NSString *)params
{
NSURL* url=[[NSURL alloc] initWithString:server];
NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
[url release];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
connectionResponse=[[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self] autorelease];
//NSURLConnection *connectionResponse = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
if (!connectionResponse)
{
NSLog(@"Failed to submit request");
}
else
{
NSLog(@"---------Report Request submitted ---------");
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(@"report received response");
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"report failed with error");
NSLog(@"%@", [error description]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"Promo View Reported");
}
-(void)dealloc
{
[connectionResponse release];
[super dealloc];
}
명확하게하기 위해 :이 코드는 모두 주 스레드가 아닌 다른 스레드에서 실행되고 있습니까? – JeremyP
글쎄 거기 UIView 주 스레드에서 실행하고 httprequest 코드는이 UIView 클래스의 인스턴스에있었습니다. 이 HTTP 요청 클래스 비동기 urlconnection 그것을 호출하는 부모 UIView 함수를 완료 한 전에 호출 된 메서드를 실행하는 완료된 후에 종료 믿습니다. 그래서 나는 그것이 주 스레드에 있다고 생각하지 않지만 그것을 호출 한 클래스는 그렇다고 생각합니다. 나는 여기서 벗어날 수 있었지만, 이것은 나에게 상당히 새로운 것이었고 나는 여전히 배우고있다. – dubbeat