gpt4 book ai didi

ios - connectionDidFinishLoading 没有被调用,为什么?

转载 作者:行者123 更新时间:2023-11-29 11:00:34 25 4
gpt4 key购买 nike

我发送了请求,但没有调用方法 connectionDidFinishLoading,为什么?

- (void)startHttpRequestWithCookie:(NSArray *)authCookies
{
NSURL *url = [NSURL URLWithString:@"http://test.test/mbox.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

NSDictionary* headers = [NSHTTPCookie requestHeaderFieldsWithCookies:authCookies];
[request setHTTPShouldHandleCookies:NO];
[request setHTTPMethod:@"POST"];
[request setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setAllHTTPHeaderFields:headers];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

if (connection) {
// Create the NSMutableData to hold the received data.
responseData = [NSMutableData new];
} else {
// Inform the user that the connection failed.
}
}

- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}

- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}

- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
NSString* responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"%@", responseString);
NSError *error = nil;
NSData* data = [responseString dataUsingEncoding:NSUTF8StringEncoding];

etc..
}

这是我的代码,我不明白为什么不调用connectionDidFinishLoading

非常感谢您的宝贵时间

最佳答案

尝试实现 - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 并检查响应对象中返回的值。

关于ios - connectionDidFinishLoading 没有被调用,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16066908/

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