我尝试使用这些代码,但我只收到这样的错误消息
错误消息:-NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9813
网址:- http://www.xxxxx.com/XXX/rest/files/downloadFile/en/linto/
header :-内容类型:application/x-www-form-urlencoded
RAW:-phoneNumber=%2B15163120019&uname=test
响应头:服务器:Apache-Coyote/1.1
内容类型:文本/xml
传输编码:分块
日期: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];
最佳答案
尽量不写斜线
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/"];
关于ios - iOS 9 中的 POST 值获取错误(NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9813),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35594829/