先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Web前端全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
如果你需要这些资料,可以添加V获取:vip1024c (备注前端)
正文
自动验证
自动验证状态码在200-300之间的区间,且内容类型是响应能接受的匹配类型。
Alamofire.request(“https://httpbin.org/get”).validate().responseJSON { response in
switch response.result {
case .success:
print(“Validation Successful”)
case .failure(let error):
print(error)
}
}
响应缓存
响应缓存依赖于系统框架URLCache.
HTTP 请求方式
HTTP请求方式的枚举列表在下面的文件定义 RFC 7231 §4.3 :
public enum HTTPMethod: String {
case options = “OPTIONS”
case get = “GET”
case head = “HEAD”
case post = “POST”
case put = “PUT”
case patch = “PATCH”
case delete = “DELETE”
case trace = “TRACE”
case connect = “CONNECT”
}
上面的那些方式的值可以当做Alamofire.request的method的参数设置
Alamofire.request(“https://httpbin.org/get”) // method defaults to `.get`
Alamofire.request(“https://httpbin.org/post”, method: .post)
Alamofire.request(“https://httpbin.org/put”, method: .put)
Alamofire.request(“https://httpbin.org/delete”, method: .delete)
默认是Get方式
参数编码
Alamofire支持三种类型的参数编码包括:URL、JSON和PropertyList。它还可以支持任何自定义编码符合ParameterEncoding协议。
URL Encoding
GET请求的URL编码
let parameters: Parameters = [“foo”: “bar”]
// All three of these calls are equivalent
Alamofire.request(“https://httpbin.org/get”, parameters: parameters) // encoding defaults to `URLEncoding.default`
Alamofire.request(“https://httpbin.org/get”, parameters: parameters, encoding: URLEncoding.default)
Alamofire.request(“https://httpbin.org/get”, parameters: parameters, encoding: URLEncoding(destination: .methodDependent))
// https://httpbin.org/get?foo=bar
POST请求的URL编码
let parameters: Parameters = [
“foo”: “bar”,
“baz”: [“a”, 1],
“qux”: [
“x”: 1,
“y”: 2,
“z”: 3
]
]
// All three of these calls are equivalent
Alamofire.request(“https://httpbin.org/post”, method: .post, parameters: parameters)
Alamofire.request(“https://httpbin.org/post”, method: .post, parameters: parameters, encoding: URLEncoding.default)
Alamofire.request(“https://httpbin.org/post”, method: .post, parameters: parameters, encoding: URLEncoding.httpBody)
// HTTP body: foo=bar&baz[]=a&baz[]=1&qux[x]=1&qux[y]=2&qux[z]=3
JSON Encoding
let parameters: Parameters = [
“foo”: [1,2,3],
“bar”: [
“baz”: “qux”
]
]
// Both calls are equivalent
Alamofire.request(“https://httpbin.org/post”, method: .post, parameters: parameters, encoding: JSONEncoding.default)
Alamofire.request(“https://httpbin.org/post”, method: .post, parameters: parameters, encoding: JSONEncoding(options: []))
// HTTP body: {“foo”: [1, 2, 3], “bar”: {“baz”: “qux”}}
Property List Encoding
PropertyListEncoding使用PropertyListSerialization创建一个参数对象的plist表示,根据相关的格式和写作选项值,设置为请求的主体。content - type HTTP请求头字段的编码设置为 application/x-plist
.。
Custom Encoding
struct JSONStringArrayEncoding: ParameterEncoding {
private let array: [String]
init(array: [String]) {
self.array = array
}
func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest {
var urlRequest = try urlRequest.asURLRequest()
let data = try JSONSerialization.data(withJSONObject: array, options: [])
if urlRequest.value(forHTTPHeaderField: “Content-Type”) == nil {
urlRequest.setValue(“application/json”, forHTTPHeaderField: “Content-Type”)
}
urlRequest.httpBody = data
return urlRequest
}
}
给URLRequest 的参数手动编码
let url = URL(string: “https://httpbin.org/get”)!
var urlRequest = URLRequest(url: url)
let parameters: Parameters = [“foo”: “bar”]
let encodedURLRequest = try URLEncoding.queryString.encode(urlRequest, with: parameters)
HTTP Headers(请求头)
给一个请求添加一个自定义的请求头,这个请求头必须是全局的,在你请求的时候更容易去获取和改变请求头。
let headers: HTTPHeaders = [
“Authorization”: “Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==”,
“Accept”: “application/json”
]
Alamofire.request(“https://httpbin.org/headers”, headers: headers).responseJSON { response in
debugPrint(response)
}
身份认证
Authentication依赖于 URLCredential
和URLAuthenticationChallenge
.这两个系统框架。
Supported Authentication Schemes
HTTP Basic Authentication
let user = “user”
let password = “password”
Alamofire.request(“https://httpbin.org/basic-auth/\(user)/\(password)”)
.authenticate(user: user, password: password)
.responseJSON { response in
debugPrint(response)
}
根据服务器的实现方法,也可能需要一个授权头
let user = “user”
let password = “password”
var headers: HTTPHeaders = [:]
if let authorizationHeader = Request.authorizationHeader(user: user, password: password) {
headers[authorizationHeader.key] = authorizationHeader.value
}
Alamofire.request(“https://httpbin.org/basic-auth/user/password”, headers: headers)
.responseJSON { response in
debugPrint(response)
}
证书认证
let user = “user”
let password = “password”
let credential = URLCredential(user: user, password: password, persistence: .forSession)
Alamofire.request(“https://httpbin.org/basic-auth/\(user)/\(password)”)
.authenticate(usingCredential: credential)
.responseJSON { response in
debugPrint(response)
}
下载文件
Alamofire.download(“https://httpbin.org/image/png”).responseData { response in
if let data = response.result.value {
let image = UIImage(data: data)
}
}
下载文件目的地
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileURL = documentsURL.appendingPathComponent(“pig.png”)
return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
}
Alamofire.download(urlString, to: destination).response { response in
print(response)
if response.error == nil, let imagePath = response.destinationURL?.path {
let image = UIImage(contentsOfFile: imagePath)
}
}
你也可以使用建议目的地的API.
let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory)
Alamofire.download(“https://httpbin.org/image/png”, to: destination)
下载进度
Alamofire.download(“https://httpbin.org/image/png”)
.downloadProgress { progress in
print(“Download Progress: \(progress.fractionCompleted)”)
}
.responseData { response in
if let data = response.result.value {
let image = UIImage(data: data)
}
}
下载进度的API还可以设置线程参数,线程参数可以决定下载进度在哪个线程调起。
let utilityQueue = DispatchQueue.global(qos: .utility)
Alamofire.download(“https://httpbin.org/image/png”)
.downloadProgress(queue: utilityQueue) { progress in
print(“Download Progress: \(progress.fractionCompleted)”)
}
.responseData { response in
if let data = response.result.value {
let image = UIImage(data: data)
}
}
恢复下载
class ImageRequestor {
private var resumeData: Data?
private var image: UIImage?
func fetchImage(completion: (UIImage?) -> Void) {
guard image == nil else { completion(image) ; return }
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileURL = documentsURL.appendingPathComponent(“pig.png”)
return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
}
let request: DownloadRequest
if let resumeData = resumeData {
request = Alamofire.download(resumingWith: resumeData)
} else {
request = Alamofire.download(“https://httpbin.org/image/png”)
}
request.responseData { response in
switch response.result {
case .success(let data):
self.image = UIImage(data: data)
case .failure:
刷面试题
刷题的重要性,不用多说。对于应届生或工作年限不长的人来说,刷面试题一方面能够尽可能地快速自己对某个技术点的理解,另一方面在面试时,有一定几率被问到相同或相似题,另外或多或少也能够为自己面试增加一些自信心,可见适当的刷题是很有必要的。
-
前端字节跳动真题解析
-
【269页】前端大厂面试题宝典
最后平时要进行自我分析与评价,做好职业规划,不断摸索,提高自己的编程能力和抽象思维能力。大厂面试远没有我们想的那么困难,摆好心态,做好准备,你也可以的。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
eData { response in
switch response.result {
case .success(let data):
self.image = UIImage(data: data)
case .failure:
刷面试题
刷题的重要性,不用多说。对于应届生或工作年限不长的人来说,刷面试题一方面能够尽可能地快速自己对某个技术点的理解,另一方面在面试时,有一定几率被问到相同或相似题,另外或多或少也能够为自己面试增加一些自信心,可见适当的刷题是很有必要的。
-
前端字节跳动真题解析
-
【269页】前端大厂面试题宝典
最后平时要进行自我分析与评价,做好职业规划,不断摸索,提高自己的编程能力和抽象思维能力。大厂面试远没有我们想的那么困难,摆好心态,做好准备,你也可以的。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
[外链图片转存中…(img-EVwBAIRh-1713189823486)]
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!