工作的结果应该是给用户的文本消息,由于某种原因出现2次,来自Android应用程序的Java代码发送1个短信,因此排除服务器问题
let url2=URL(string:"url="+PhoneTextField.text!)
let config = URLSessionConfiguration.default
let userPasswordString = "user:pass"
let userPasswordData = userPasswordString.data(using: String.Encoding.utf8)
let base64EncodedCredential = userPasswordData!
let authString = "Basic \(base64EncodedCredential)"
config.httpAdditionalHeaders = ["Authorization" : authString]
config.requestCachePolicy = .reloadIgnoringLocalCacheData
config.urlCache = nil
URLCache.shared.removeAllCachedResponses()
let session = URLSession.init(configuration: config)
let task=session.dataTask(with: url2!){
( data, response, error) in
let dataString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
self.dataStringJSon=dataString as String?
if(self.dataStringJSon!=="User not found"){
}else{
DispatchQueue.main.async {
let storyboard = UIStoryboard(name: "Main", bundle: nil);
let vc = storyboard.instantiateViewController(withIdentifier: "MySecondSecreen") as! UIViewController;
self.present(vc, animated: true, completion: nil);
}
}
}
task.resume()
答案 0 :(得分:0)
使用会话配置禁用缓存
config.requestCachePolicy = .reloadIgnoringLocalCacheData
config.urlCache = nil