所以这可能有点宽泛,但我会尽可能具体地了解我正在做的事情。
目前我正在使用swift 3开发iPhone应用程序。此应用程序对位于不同网络上的灯服务器上的php文件执行发布请求。服务器主要用于简单地从应用程序发送数据并将其存储到某些mysql表中。
目前,我正在这样做。
func sendToServer(firstEntry: String, secondEntry: String, serverAddr: String){
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration, delegate: self, delegateQueue: OperationQueue.main)
let uid = firstEntry
let gender = secondEntry
let request = NSMutableURLRequest(url: NSURL(string: serverAddr)! as URL)
request.httpMethod = "POST"
let postString = "UID=\(uid)&Gender=\(gender)"
request.httpBody = postString.data(using: String.Encoding.utf8)
let task = session.dataTask(with: request as URLRequest) {
data, response, error in
if error != nil {
print("error=\(error)")
return
}
print("response = \(response)")
let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
print("responseString = \(responseString)")
}
task.resume()
}
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
completionHandler(URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
}
这样就可以发送数据。但我想看看是否有人可以回答这些问题。
有没有办法在没有域名的情况下获得可信证书?
如果我以这种方式这样做,那么应用程序会因为此被拒绝而存在问题吗?
由于