gpt4 book ai didi

ios - 在 iOS 中检索 HTTPResponse/HTTPRequest 状态代码?

转载 作者:IT王子 更新时间:2023-10-29 07:51:02 25 4
gpt4 key购买 nike

我需要检查和评估我的 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,因此这可能对您没有帮助。但我还是希望它能做到!

关于ios - 在 iOS 中检索 HTTPResponse/HTTPRequest 状态代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/917932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com