我有一个ios(swift)项目,该项目使用alamofire向服务器请求。
当使用“ https” URL调用api时,我得到401响应,但是当使用“ http”时,它工作正常,并且在具有相同标头和url的邮递员中,我得到了https和http的结果,并且我确定问题出在应用不是api。
和api调用者:
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 300
configuration.timeoutIntervalForResource = 300
self.alamoFire = Alamofire.SessionManager(configuration: configuration)
self.alamoFire.request(url, method: .get, encoding: JSONEncoding.default, headers: self.GetRequestsHeader)
.validate(statusCode: 200..<300)
.responseJSON
{ (response) in
if (response.response?.statusCode == 401){
DataStorage().save(key: DataStorageEnum.Session.rawValue, value: "")
}
else if let session = response.response?.allHeaderFields[RequestsHeaderEnum.FSession.rawValue] as? String {
DataStorage().save(key: DataStorageEnum.Session.rawValue, value: session)
}
switch response.result
{
case .success:
if let jsonData = response.data
{
do
{
returnValue = try JSONDecoder().decode(type(of: returnValue), from: jsonData)
complition(returnValue)
}
catch let error
{
self._Logger.Log(errorMessage: error.localizedDescription, fileName: #file, functionName: #function, lineNumber: String(#line))
complition(returnValue)
}
}
case .failure(let error):
self._Logger.Log(errorMessage: error.localizedDescription, fileName: #file, functionName: #function, lineNumber: String(#line))
complition(returnValue)
}
}