J.D*_*Doe 5 ios nsurlsession swift
我请求一个带有此代码的网页
URLSession.shared.dataTask(with: NSURL(string: url)! as URL, completionHandler: { (data, response, error) -> Void in
if error == nil && data != nil {
// No error
}else{
// Error
if let httpResponse = response as? HTTPURLResponse {
print(httpResponse.statusCode)
}
}
Run Code Online (Sandbox Code Playgroud)
我试图通过将响应强制转换为请求页面时获取错误代码,HTTPURLResponse但强制转换不起作用并且不执行打印。你知道我怎样才能得到代码吗?
| 归档时间: |
|
| 查看次数: |
3592 次 |
| 最近记录: |