Guest User

Untitled

a guest
Dec 17th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. let params : [String : Any] =["param1":param1,"param2":param2]
  2. let headers : HTTPHeaders = ["authorization" : apiKey]
  3.  
  4. Alamofire.request(MY_URL, method: .post, parameters: params, headers: headers).responseJSON {
  5. response in
  6. switch response.result{
  7. case .success(let result):
  8.  
  9. //other code here
  10. }
  11.  
  12. $app->map('/MY_URL','authenticate',function ()use($app){
  13.  
  14. }
  15.  
  16. let headers: HTTPHeaders = [
  17. "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
  18. "Accept": "application/json"
  19. ]
  20.  
  21. Alamofire.request("https://httpbin.org/headers", headers: headers).responseJSON { response in
  22. debugPrint(response)
  23. }
  24.  
  25. let url = "WEB API URL"
  26. let headers = [
  27. "Content-Type":"application/x-www-form-urlencoded",
  28. "authorization" : "apiKey"
  29. ]
  30.  
  31. let configuration = URLSessionConfiguration.default
  32. configuration.requestCachePolicy = .reloadIgnoringLocalCacheData
  33. let params : [String : Any] = ["param1":param1,"param2":param2]
  34.  
  35. Alamofire.request(url, method: .post, parameters: params as? Parameters, encoding: URLEncoding.httpBody, headers: headers).responseJSON { response in
  36.  
  37. if let JSON = response.result.value {
  38. print("JSON: (JSON)")
  39.  
  40. }else{
  41. print("Request failed with error: ",response.result.error ?? "Description not available :(")
  42.  
  43. }
  44. }
  45.  
  46. ["Authorization": "Bearer <#your_token#>"]
  47.  
  48. $ curl -i http://localhost/slim-token-authentication/example/restrict -H "Authorization: Bearer usertokensecret"
  49.  
  50. /// Creates a `DataRequest` using the default `SessionManager` to retrieve the contents of the specified `url`,
  51. /// `method`, `parameters`, `encoding` and `headers`.
  52. ///
  53. /// - parameter url: The URL.
  54. /// - parameter method: The HTTP method. `.get` by default.
  55. /// - parameter parameters: The parameters. `nil` by default.
  56. /// - parameter encoding: The parameter encoding. `URLEncoding.default` by default.
  57. /// - parameter headers: The HTTP headers. `nil` by default.
  58. ///
  59. /// - returns: The created `DataRequest`.
  60. public func request(_ url: URLConvertible, method: Alamofire.HTTPMethod = default, parameters: Parameters? = default, encoding: ParameterEncoding = default, headers: HTTPHeaders? = default) -> Alamofire.DataRequest
  61.  
  62. Alamofire.request("https://...",
  63. method: .get,
  64. parameters: ["myKey1": "myValue1"],
  65. encoding: JSONEncoding.default,
  66. headers: self.authHeader).responseJSON { response in
  67. //your response
  68. }
Add Comment
Please, Sign In to add comment