有没有办法在iOS中的NSURLRequest中访问'Date'HTTP标头,例如在授权过程中使用它? (例如http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html)
答案 0 :(得分:0)
试试此代码
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()