문제

iPhone 앱에서 HTTP 상태 코드를 확인하고 평가해야합니다. NSURLREQUEST 객체와 NSURLConnection이있어 사이트에 성공적으로 연결됩니다.

// create the request
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]
                        cachePolicy:NSURLRequestUseProtocolCachePolicy
                    timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
    // Create the NSMutableData that will hold
    // the received data
    // receivedData is declared as a method instance elsewhere
    receivedData=[[NSMutableData data] retain];
} else {
    // inform the user that the download could not be made
}

이 코드를 여기에 얻었습니다. https://web.archive.org/web/20100908130503/http://developer.apple.com/iphone/library/documentation/cocoa/conceptual/urlloadingsystem/tasks/usingnsurlconnection.html

그러나 (내가 볼 수있는 한) HTTP 상태 코드 액세스에 대해 아무 말도하지 않습니다.

사이트에 연결 한 다음 해당 연결의 HTTP 상태 코드를 확인하는 방법은 무엇입니까?

도움이 되었습니까?

해결책

이것이 내가하는 방법입니다.

    #pragma mark -
    #pragma mark NSURLConnection Delegate Methods
    - (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response {
         NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
         int responseStatusCode = [httpResponse statusCode];
    }

그러나 나는 비동기식 nsurlconnection을 사용하고 있으므로 도움이되지 않을 수 있습니다. 그러나 나는 어쨌든 그것이되기를 바랍니다!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top