使用未解析的标识符 'response'(在“"dataTask.resume()"”之后)
Use of unresolved identifier 'response' (after """dataTask.resume()""")
我想我需要在别处写我的 class 但我不知道在哪里。
错误显示在最后 dataTask.resume()
之后的行。
let postData = NSMutableData(data: "email=hello@test.com".data(using: String.Encoding.utf8)!)
postData.append("&password=12345".data(using: String.Encoding.utf8)!)
postData.append("&loginbutton=Connecter".data(using: String.Encoding.utf8)!)
let request = NSMutableURLRequest(url: NSURL(string: "https://zzzway.com/appMango/login.php")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()
let httpResponse = response as? HTTPURLResponse
if httpResponse.contains("chute")
{
print("exists")
}
这个
let httpResponse = response as? HTTPURLResponse
if httpResponse.contains("chute") {
print("exists")
}
应该在completionHandler
里面
完成你需要做的事情
if let str = response?.url?.absoluteString , str.contains("chute") {
}
我想我需要在别处写我的 class 但我不知道在哪里。
错误显示在最后 dataTask.resume()
之后的行。
let postData = NSMutableData(data: "email=hello@test.com".data(using: String.Encoding.utf8)!)
postData.append("&password=12345".data(using: String.Encoding.utf8)!)
postData.append("&loginbutton=Connecter".data(using: String.Encoding.utf8)!)
let request = NSMutableURLRequest(url: NSURL(string: "https://zzzway.com/appMango/login.php")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()
let httpResponse = response as? HTTPURLResponse
if httpResponse.contains("chute")
{
print("exists")
}
这个
let httpResponse = response as? HTTPURLResponse
if httpResponse.contains("chute") {
print("exists")
}
应该在completionHandler
完成你需要做的事情
if let str = response?.url?.absoluteString , str.contains("chute") {
}