我得到一些SSL Errors(这导致我的项目停止/挂起而没有崩溃,因为我DispatchGroup等待请求),我不知道它们是如何引起的,它们是什么,或者该怎么做.
我看过无数的网页大概这个问题,但目前还没有太多的文件或具有相同问题的人.我试过更改info.plist,但似乎没有帮助.两者都是plist这样的:( accounts.spotify.com是访问令牌请求的URL的域)
当我向服务器发出请求时,我可以看到我的代码失败了.(这是我的框架).如前所述,我DispatchGroup等待这个请求但代码停止了.
self.currentToken = try self.spotifyRequest("https://accounts.spotify.com/api/token", method: .post, parameters: parameters)
Run Code Online (Sandbox Code Playgroud)
我的要求方法:
private func spotifyRequest(_ url: URLConvertible, method: HTTPMethod, parameters: Parameters? = nil, headers: HTTPHeaders? = nil) throws -> JSONStandard {
// Create a dispatch group to handle threads
let group = DispatchGroup()
group.enter()
// Status of the request (starts as nil)
var status: JSONStandard?
DispatchQueue.global(qos: .userInitiated).async {
Alamofire.request(url, method: method, parameters: parameters, headers: headers).responseJSON(completionHandler: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我的应用程序建立到服务器的HTTPS连接.但由于跟随错误,连接失败
错误域= NSURLErrorDomain代码= -1200"发生SSL错误,无法与服务器建立安全连接." UserInfo = 0x612eb30 {NSErrorFailingURLStringKey = https:myURL.com/signup,NSLocalizedRecoverySuggestion =您是否还要连接到服务器?,NSErrorFailingURLKey = https:myURL.com/signup,NSLocalizedDescription =发生了SSL错误并且安全连接到服务器无法生成.,NSUnderlyingError = 0x612eb70"发生SSL错误,无法建立与服务器的安全连接."}
连接到服务器的代码是
-(IBAction) handleEvents:(id)sender
{
if ((UIButton*)sender == submit) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSLog(@"Begin");
NSData *urlData;
NSURLResponse *response;
NSError *error;
NSString *url =[[NSString alloc]initWithFormat:@"%@signup",baseURL];
NSURL *theURL =[NSURL URLWithString:url];
NSMutableURLRequest *theRequest =[NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:0.0f];
[theRequest setHTTPMethod:@"POST"];
NSString *theBodyString = [NSString stringWithFormat:@"emailId=%@&mobileNumber=%@&appId=%@&password=%@&firstName=%@&lastName=%@"
,@"abc@example.com",@"919879876780",@"bf1c7a6b3d266a7fe350fcfc4dda275211c13c23" ,@"qwerty" , @"Dev" , @"Sri"];
NSData *theBodyData = [theBodyString dataUsingEncoding:NSUTF8StringEncoding];
[theRequest setHTTPBody:theBodyData];
urlData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
}
}
Run Code Online (Sandbox Code Playgroud)
我的委托方法是
- …Run Code Online (Sandbox Code Playgroud) 我收到自签名证书的错误
错误域= NSURLErrorDomain代码= -1200"发生SSL错误,无法与服务器建立安全连接.
同时测试我的一个演示应用程序的Web服务
注意: 在假设其重复之前,我会请求请一直阅读,即使我已向苹果开发论坛报告过
使用Alamofire图书馆
func testAlamofireGETRequest() -> Void
{
Alamofire.request(.GET, "https://filename.hostname.net/HelloWeb/service/greeting/john")
.responseJSON
{ response in
print("Response JSON: \(response.result.value)")
}
}
Run Code Online (Sandbox Code Playgroud)
使用NSURLSession
func testNSURLSessionRequest() -> Void {
let session = NSURLSession.sharedSession()
let urlString = "https://filename.hostname.net/HelloWeb/service/greeting/john"
let url = NSURL(string: urlString)
let request = NSURLRequest(URL: url!)
let dataTask = session.dataTaskWithRequest(request) { (data:NSData?, response:NSURLResponse?, error:NSError?) -> Void in
print("done, error: \(error)")
//Error Domain=NSURLErrorDomain Code=-1200 "An …Run Code Online (Sandbox Code Playgroud) 我安装了Xcode 7并尝试在iOS 9下运行我的应用程序.我收到臭名昭着的错误:Connection failed! Error - -1200 An SSL error has occurred and a secure connection to the server cannot be made.
事情是我的服务器支持TLSv1.2并且我正在使用NSURLSession.
那可能是什么问题呢?
我想下载一个带有a的文件NSURLRequest并将其保存但与该行一起保存
NSData * data = ... 发生错误.
NSURL *Urlstring = [NSURL URLWithString:@"http://yourdomain.com/yourfile.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL: Urlstring];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
documentsURL = [documentsURL URLByAppendingPathComponent:@"localFile.pdf"];
[data writeToURL:documentsURL atomically:YES];
Run Code Online (Sandbox Code Playgroud)
警告消息是我应该使用NSURLSession dataTaskwithrequest"因为sendSynchronousRequest在iOS 9中已弃用,但这不起作用我希望有人可以帮助我
此代码尝试访问并且无法访问在浏览器中工作的SSL URL:
let path = "https://localhost:8443/greeting"
let request = NSMutableURLRequest(URL: NSURL(string: path)!)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
let json:JSON = JSON(data: data!)
if let c = json["content"].string {
print(c)
}
})
task.resume()
Run Code Online (Sandbox Code Playgroud)
失败并出现错误:
可选(错误域= NSURLErrorDomain代码= -1200"发生SSL错误,无法建立与服务器的安全连接."UserInfo = {NSURLErrorFailingURLPeerTrustErrorKey =,
允许应用程序接受此证书需要什么?
有问题的证书是自签名的.在SO上阅读一些解决方案但没有成功.
运行Xcode 7.2
学习新技术是一个耗时的过程。它适用于带有 Java 的 Android。这又是针对带有 Swift 的 iOS 的。我现在面临着需要为 Android 和 iOS 应用程序提供服务器后端的挑战。但是,如果可能的话,我想避免学习一门新语言的大量时间投入。据我所知,服务器代码可以用 Java 或 Swift 编写,但 Swift 似乎是一种更简洁的语言,所以这就是我选择走这条路的原因。
我想制作一个概念验证示例,其中运行 Swift 的服务器能够与 Android 和 iOS 应用程序进行通信。应用程序发送请求并接收响应。
这个问题和我在下面的回答是我对服务器端 Swift 的介绍。
ios ×6
swift ×4
nsurlsession ×3
ssl ×3
alamofire ×2
ios9 ×2
android ×1
boringssl ×1
https ×1
nsurlrequest ×1
objective-c ×1
spotify ×1
xcode ×1