Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let params : [String : Any] =["param1":param1,"param2":param2]
- let headers : HTTPHeaders = ["authorization" : apiKey]
- Alamofire.request(MY_URL, method: .post, parameters: params, headers: headers).responseJSON {
- response in
- switch response.result{
- case .success(let result):
- //other code here
- }
- $app->map('/MY_URL','authenticate',function ()use($app){
- }
- let headers: HTTPHeaders = [
- "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
- "Accept": "application/json"
- ]
- Alamofire.request("https://httpbin.org/headers", headers: headers).responseJSON { response in
- debugPrint(response)
- }
- let url = "WEB API URL"
- let headers = [
- "Content-Type":"application/x-www-form-urlencoded",
- "authorization" : "apiKey"
- ]
- let configuration = URLSessionConfiguration.default
- configuration.requestCachePolicy = .reloadIgnoringLocalCacheData
- let params : [String : Any] = ["param1":param1,"param2":param2]
- Alamofire.request(url, method: .post, parameters: params as? Parameters, encoding: URLEncoding.httpBody, headers: headers).responseJSON { response in
- if let JSON = response.result.value {
- print("JSON: (JSON)")
- }else{
- print("Request failed with error: ",response.result.error ?? "Description not available :(")
- }
- }
- ["Authorization": "Bearer <#your_token#>"]
- $ curl -i http://localhost/slim-token-authentication/example/restrict -H "Authorization: Bearer usertokensecret"
- /// Creates a `DataRequest` using the default `SessionManager` to retrieve the contents of the specified `url`,
- /// `method`, `parameters`, `encoding` and `headers`.
- ///
- /// - parameter url: The URL.
- /// - parameter method: The HTTP method. `.get` by default.
- /// - parameter parameters: The parameters. `nil` by default.
- /// - parameter encoding: The parameter encoding. `URLEncoding.default` by default.
- /// - parameter headers: The HTTP headers. `nil` by default.
- ///
- /// - returns: The created `DataRequest`.
- public func request(_ url: URLConvertible, method: Alamofire.HTTPMethod = default, parameters: Parameters? = default, encoding: ParameterEncoding = default, headers: HTTPHeaders? = default) -> Alamofire.DataRequest
- Alamofire.request("https://...",
- method: .get,
- parameters: ["myKey1": "myValue1"],
- encoding: JSONEncoding.default,
- headers: self.authHeader).responseJSON { response in
- //your response
- }
Add Comment
Please, Sign In to add comment