小编jla*_*law的帖子

Swift:如何使用自签名证书请求URL?

我正在打开一个SSL连接以在Swift中检索JSON,但我正在使用自签名证书对我自己的服务器进行测试.以下是网址请求的摘要:

var urlPath = "https://myhost.com/get_json"
var url: NSURL = NSURL(string: urlPath)
var request: NSURLRequest = NSURLRequest(URL: url)
var connection: NSURLConnection = NSURLConnection(request: request, delegate: self, startImmediately: false)        
connection.start()
Run Code Online (Sandbox Code Playgroud)

但是,由于证书,它被拒绝(正确):

Opening connection to https://myhost.com/get_json
2014-06-05 09:37:02.543 AppName[44835:3182593] NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
Connection failed.The certificate for this server is invalid. You might be connecting to a server that is pretending to be “myhost.com” which could put your confidential information at risk.## Heading ##
Run Code Online (Sandbox Code Playgroud)

ssl json swift

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

json ×1

ssl ×1

swift ×1