Ios 阿拉莫菲尔和文摘作者

Ios 阿拉莫菲尔和文摘作者,ios,alamofire,swift4.2,digest-authentication,Ios,Alamofire,Swift4.2,Digest Authentication,我正在尝试在我的应用程序摘要auth中实现,但我正在努力,或者工作不正常 我已按照您在AuthenticationTestCase中的描述设置了我的请求,代码如下: let userName = "***********" let password = "***********" let qop = "auth" let xmlStr: String = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><

我正在尝试在我的应用程序摘要auth中实现,但我正在努力,或者工作不正常

我已按照您在
AuthenticationTestCase
中的描述设置了我的请求,代码如下:

let userName = "***********"
let password = "***********"
let qop = "auth"
let xmlStr: String = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>authenticate.login</methodName></methodCall>"
let postData:Data = xmlStr.data(using:  String.Encoding.utf8, allowLossyConversion: true)!
let url = URL(string: "https://app.**********.co.uk/service/mobile/digest-auth/\(qop)/\(userName)/\(password)")
var request = URLRequest(url: url!)
request.httpShouldHandleCookies = true 
request.setValue("\(String(describing: xmlStr))", forHTTPHeaderField: "Content-Length")
request.setValue("application/xml", forHTTPHeaderField: "Content-Type")
request.setValue("IOS133928234892nil", forHTTPHeaderField: "User-Agent")
request.setValue("application/xml", forHTTPHeaderField: "Accept")
request.httpMethod = "POST"
request.httpBody = postData 
     AF.request(request)
         .authenticate(username: userName, password: password)
         .response { response in ........
注意:如果我通过邮递员发出同样的请求,它会正常工作。 看起来Alamofire没有正确处理摘要挑战

你能帮我解决这个问题吗

Response XML Error:
You must be authenticated to access this resource

Response Error Code: 401

Response Headers:
Optional([AnyHashable("X-Powered-By"): PHP/7.1.33, AnyHashable("Pragma"): no-cache, AnyHashable("Content-Length"): 310, AnyHashable("Date"): Fri, 22 May 2020 09:15:48 GMT, AnyHashable("Server"): Apache/2.4.41 () OpenSSL/1.0.2k-fips PHP/7.1.33, AnyHashable("Cache-Control"): no-store, no-cache, must-revalidate, AnyHashable("Content-Type"): Content-Type: application/xml, AnyHashable("Www-Authenticate"): Digest realm="Mobile",nonce="31JEmMdeSVfXWQ:OT/ndHY6ch/PjqFwA6uutg",opaque="c81e728d9d4c2f636f067f89cc14864c",qop="auth",algorithm="MD5", Digest realm="Mobile",nonce="31JEmMdeSVfXWQ:OT/ndHY6ch/PjqFwA6uutg",opaque="c81e728d9d4c2f636f067f89cc14864c",qop="auth",algorithm="SHA-512-256", Digest realm="Mobile",nonce="31JEmMdeSVfXWQ:OT/ndHY6ch/PjqFwA6uutg",opaque="c81e728d9d4c2f636f067f89cc14864c",qop="auth",algorithm="SHA-256", AnyHashable("Connection"): Keep-Alive, AnyHashable("Keep-Alive"): timeout=5, max=100, AnyHashable("Expires"): Thu, 19 Nov 1981 08:52:00 GMT])