我尝试使用这些代码,但我收到的错误消息只有这些
错误消息:-NSURLSession / NSURLConnection HTTP加载失败(kCFStreamErrorDomainSSL,-9813
网址: - http://www.xxxxx.com/XXX/rest/files/downloadFile/en/linto/
标题: - 内容类型:application / x-www-form-urlencoded
RAW: - phoneNumber =%2B15163120019& uname = test
响应标题:服务器:Apache-Coyote / 1.1
Content-Type:text / xml
Transfer-Encoding:chunked
日期:2016年2月24日星期三05:03:05 GMT 生的 解析的
XCODE版本:7.2.1 我的代码: -
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
NSURL * url = [NSURL URLWithString:@"https://www.indusaudio.com/WeeAudio/rest/files/downloadFile/en/linto/"];
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSString * params =@"phoneNumber=%2B15163120019&uname=test";
[urlRequest setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
[urlRequest setHTTPMethod:@"POST"];
NSURLSessionDataTask * dataTask =[defaultSession dataTaskWithRequest:urlRequest
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"Response:%@ %@\n", response, error);
if(error == nil)
{
// NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
//NSLog(@"Data = %@",text);
}
}];
[dataTask resume];
}
答案 0 :(得分:1)
尝试不带斜线编写此行
NSURL * url = [NSURL URLWithString:@"https://www.indusaudio.com/WeeAudio/rest/files/downloadFile/en/linto/"];
到
NSURL * url = [NSURL URLWithString:@"http://www.indusaudio.com/WeeAudio/rest/files/downloadFile/en/linto/"];
答案 1 :(得分:0)
iOS9要求服务器仅支持TLSv1.2,必须在app plist中进行异常添加才能解决。
在.plist
:
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>