浏览代码

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

Christian Noon 10 年之前
父节点
当前提交
dfd4ac1102
共有 1 个文件被更改,包括 19 次插入0 次删除
  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