我已经发送了一个带有访问令牌的请求。我得到了一个错误响应。
[Response]:
[Status Code]: 401
{"response":{"success":"false","result":{"errorCode":"4012001002","message":"Invalid token / expired."}}}
字符串
下面我添加了代码…
import UIKit
import Alamofire
import SwiftKeychainWrapper
class HelpViewController: UIViewController{
var ticketResult = [TicketResponse]()
let tokens: String? = KeychainWrapper.standard.string(forKey: "accessToken")
override func viewDidLoad()
{
super.viewDidLoad()
HistoryAPI()
}
func HistoryAPI() {
if tokens != nil
{
print("Hello Access Token \(String(describing: tokens))")
let headers: HTTPHeaders = [
"content-type": "application/json",
"correlationId": "myYt005",
"operation": "ticketDetail",
"destination": "CRM",
"source": "WEB",
"srDate": "16-05-2022",
"token": "\(String(describing: tokens))"
// "token": "\(String(describing: token))"
]
AF.request(ticketHistory_url, method: .get, headers: headers).response { response in
debugPrint(response)
switch response.result {
case .success(let data):
if let ticketData = data as? [TicketResponse] {
self.ticketResult = ticketData
}
case .failure(let error):
print("Error: \(error.localizedDescription)")
// Handle the error if needed
}}}
}
}
型
1条答案
按热度按时间jv4diomz1#
尝试使用正确的令牌头密钥“Authorization”
字符串