gpt4 book ai didi

ios - 为什么我在 NSURLSession 上收到 SSL_ERROR_ZERO_RETURN 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:29:17 26 4
gpt4 key购买 nike

这是我的代码,我没有在任何地方使用 Borring SSL

NSURL* urlToRequest = [NSURL URLWithString:urlString];
NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:urlToRequest];
[urlRequest setHTTPMethod:@"GET"];

NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];

NSError *error = nil;

if (!error) {

NSURLSessionDataTask *downloadTask = [session dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (!error) {
NSHTTPURLResponse *httpResp = (NSHTTPURLResponse*) response;
if (httpResp.statusCode == 200) {
NSString *response1=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"JSON:%@",response1);
NSLog(@"Response:%@",response);
NSLog(@"Error:%@",error);

}
}
}];

[downloadTask resume];

}

这是我收到的错误,我想知道是什么导致了这个问题?

[BoringSSL] Function boringssl_session_errorlog: line 2871 [boringssl_session_read] SSL_ERROR_ZERO_RETURN(6): operation failed because the connection was cleanly shut down with a close_notify alert

我收到成功响应,但过了一段时间我收到此错误。

据我所知,这只是一个警告,我不必考虑它。

不管怎样,我得到了成功的回应。如果我错了,请纠正我

欢迎提出建议

附言当我在浏览器中复制粘贴 URL 时,我也没有看到任何错误

最佳答案

试试这个

NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
NSData *requestData = [prams dataUsingEncoding:NSUTF8StringEncoding];

[urlRequest setHTTPMethod:@“GET”];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

NSURLSessionDataTask * dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:urlRequest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
//NSLog(@"data=%@",data);

if (data.length>0 && error==nil) {
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
NSLog(@"Dict=%@",dict);


}
}];
[dataTask resume];

关于ios - 为什么我在 NSURLSession 上收到 SSL_ERROR_ZERO_RETURN 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49550093/

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