수색…
통사론
- 응답()
- responseData ()
- responseString (인코딩 : NSStringEncoding)
- responseJSON (옵션 : NSJSONReadingOptions)
- responsePropertyList (옵션 : NSPropertyListReadOptions)
매개 변수
매개 변수 | 세부 |
---|---|
방법 | .OPTIONS, .GET, .HEAD, .POST, .PUT, .PATCH, .DELETE, .TRACE, .CONNECT |
URLString | URLStringConvertible |
매개 변수들 | [String: AnyObject]? |
부호화 | ParameterEncoding |
머리말 | [String: String]? |
요청하다
import Alamofire
Alamofire.request(.GET, "https://httpbin.org/get")
자동 유효성 검사
Alamofire.request("https://httpbin.org/get").validate().responseJSON { response in
switch response.result {
case .success:
print("Validation Successful")
case .failure(let error):
print(error)
}
}
응답 처리
Alamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"])
.responseJSON { response in
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
수동 유효성 검사
Alamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"])
.validate(statusCode: 200..<300)
.validate(contentType: ["application/json"])
.response { response in
print(response)
}
응답 처리기
Alamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"])
.validate()
.response { request, response, data, error in
print(request)
print(response)
print(data)
print(error)
}
연결 응답 처리기
Alamofire.request(.GET, "https://httpbin.org/get")
.validate()
.responseString { response in
print("Response String: \(response.result.value)")
}
.responseJSON { response in
print("Response JSON: \(response.result.value)")
}
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow