import UIKit
import Alamofire
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.lightGray
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
Alamofire.request("https://baidu.com/").responseJSON { response in
print(response.request!) // 原始的URL请求
print(response.response!) // HTTP URL响应
print(response.data!) // 服务器返回的数据
print(response.result) // 响应序列化结果,在这个闭包里,存储的是JSON数据
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
}
}
https://baidu.com/
<NSHTTPURLResponse: 0x600003c54cc0> { URL: http://www.baidu.com/ } { Status Code: 200, Headers {
Bdpagetype = (
1
);
Bdqid = (
0x9fa796d400035686
);
"Cache-Control" = (
private
);
Connection = (
"keep-alive"
);
"Content-Encoding" = (
gzip
);
"Content-Type" = (
"text/html;charset=utf-8"
);
Date = (
"Wed, 29 Sep 2021 06:07:54 GMT"
);
Expires = (
"Wed, 29 Sep 2021 06:07:54 GMT"
);
Server = (
"BWS/1.1"
);
"Set-Cookie" = (
"BDSVRTM=16; path=/",
"BD_HOME=1; path=/",
"H_PS_PSSID=34649_34067_31660_34654_34584_34517_26350_34422_34691; path=/; domain=.baidu.com"
);
Traceid = (
1632895674030575463411504329610418673286
);
"Transfer-Encoding" = (
Identity
);
"X-Frame-Options" = (
sameorigin
);
"X-Ua-Compatible" = (
"IE=Edge,chrome=1"
);
} }
308929 bytes
FAILURE
网友评论