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