0
有沒有辦法在iOS中的NSURLRequest中訪問'Date'HTTP頭,例如在授權過程中使用它? (例如http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html)在iOS中的NSURLRequest中訪問'日期'HTTP頭
有沒有辦法在iOS中的NSURLRequest中訪問'Date'HTTP頭,例如在授權過程中使用它? (例如http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html)在iOS中的NSURLRequest中訪問'日期'HTTP頭
嘗試此代碼
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config)
let url = URL(string:"https://johnsmith.s3.amazonaws.com")!
let request = NSMutableURLRequest(url: url)
request.timeoutInterval = 60
request.addValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.httpMethod = "GET"
request.addValue(" "AWS" + " " + AWSAccessKeyId + ":" + Signature", forHTTPHeaderField: "Authorization")
let task = session.dataTask(with: request as URLRequest) { (data, response, error) in
// (data, response, error) in
if error != nil {
print(error!.localizedDescription)
} else {
do {
let json = try JSONSerialization.jsonObject(with: data! as Data, options: .allowFragments)
print("json data")
} catch {
print("error in JSONSerialization")
}
}
}
task.resume()