gpt4 book ai didi

swift - url 的请求通过了 2 次,虽然应该是 1 次

转载 作者:行者123 更新时间:2023-11-30 12:33:57 26 4
gpt4 key购买 nike

工作结果应该是向用户发送一条短信,由于某种原因,该短信出现了 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()

最佳答案

通过 session 配置禁用缓存

config.requestCachePolicy = .reloadIgnoringLocalCacheData
config.urlCache = nil

关于swift - url 的请求通过了 2 次,虽然应该是 1 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43112328/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com