Forráskód Böngészése

Added a basic auth `Authorization` header example to the README.

Christian Noon 10 éve
szülő
commit
dfd4ac1102
1 módosított fájl, 19 hozzáadás és 0 törlés
  1. 19 0
      README.md

+ 19 - 0
README.md

@@ -411,6 +411,8 @@ Authentication is handled on the system framework level by [`NSURLCredential` an
 
 #### HTTP Basic Authentication
 
+The `authenticate` method on a `Request` will automatically provide an `NSURLCredential` to an `NSURLAuthenticationChallenge` when appropriate:
+
 ```swift
 let user = "user"
 let password = "password"
@@ -422,6 +424,23 @@ Alamofire.request(.GET, "https://httpbin.org/basic-auth/\(user)/\(password)")
          }
 ```
 
+Depending upon your server implementation, an `Authorization` header may also be appropriate:
+
+```swift
+let user = "user"
+let password = "password"
+
+let credentialData = "\(user):\(password)".dataUsingEncoding(NSUTF8StringEncoding)!
+let base64Credentials = credentialData.base64EncodedStringWithOptions(nil)
+
+let headers = ["Authorization": "Basic \(base64Credentials)"]
+
+Alamofire.request(.GET, "http://httpbin.org/basic-auth/user/password", headers: headers)
+         .responseJSON { _, _, JSON, _ in
+             println(JSON)
+         }
+```
+
 #### Authentication with NSURLCredential
 
 ```swift