0
이 질문은 중복 된 것으로 보입니다. 문제의 해결책을 찾았습니다. 여전히NSURLSession 오류 가져 오기 "NSURLSession/NSURLConnection HTTP로드 실패 (kCFStreamErrorDomainSSL, -9813)"
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
작동하지 제안 아래 적용한 후 그들 중 몇몇 내 코드가 있는 NSURLConnection와 협력 제안했다. 서버 전송 응답
-(NSMutableURLRequest *) getRequest
{
NSURL *URL = [NSURL URLWithString:@"https://URLRequest"];
NSString *requestBody = @"username=abc&[email protected]&deviceId=646D4945-DA22-408B-B132-EFDED5430650&deviceTypeId=1&deviceName=iPad Simulator&versionInfo=Version 1.16.6 1.0.13";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request setHTTPMethod:@"POST"];
//NSData *paramData = [requestBody dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:[requestBody dataUsingEncoding:NSUTF8StringEncoding]];
[request addValue:@"1.0" forHTTPHeaderField:@"HTTP"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
return request;
}
-(void) sessionRequest
{
[NSURLConnection sendAsynchronousRequest:[self getRequest]
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
if(data)
{
NSError *jsonError = nil;
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
if (jsonError)
{
NSLog(@"Problem for download data");
}
else
{
NSLog(@"Response:%@",json);
}
}
}];
}
내가 메시지 NSURLSession /있는 NSURLConnection HTTP로드가 사람이 issue.Please 가이드를 직면
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]]; //NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *task = [session dataTaskWithRequest:[self getRequest] completionHandler: ^(NSData *data, NSURLResponse *response, NSError *error) { NSHTTPURLResponse *tempResponse = (NSHTTPURLResponse *)response; NSLog(@"statusCode:%d %@",tempResponse.statusCode,tempResponse.allHeaderFields); if(data) { NSError *jsonError = nil; id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError]; if (jsonError) { NSLog(@"Problem for download data"); } else { NSLog(@"Response:%@",json); } } }]; [task resume];
NSURLSession
와 실패 얻을.
위의 메시지 수신하지 않았다, 그것은 OS의 같은 버전에있는 NSURLConnection와 함께 작동? – dgatwood
예 동일한 버전의 iOS9.3 시뮬레이터 및 iPad 기기에서 작동합니다. –
아래 질문에서 언급 한 답변을 시도하십시오. https://stackoverflow.com/questions/39704663/getting-error-with-nsurlsession-nsurlsession-nsurlconnection-http-load-failed?noredirect=1#comment66711430_39704663 – sandy