multipart / form-data upload任务不会为iOS中的大文件调用Authentication Challenge

问题描述 投票:1回答:1

我正在尝试使用URLSession.dataTask(with: r as URLRequest)将zip文件从移动设备上传到远程Azure服务器。为此,我使用NSURLAuthenticationMethodServerTrustNSURLAuthenticationMethodClientCertificate身份验证。当zip文件的大小为~15KB时,两者工作正常。

但对于更大的文件,我只看到NSURLAuthenticationMethodServerTrust然后请求超时。我已经花了3天没有任何具体方向。

    func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {

    if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodClientCertificate{
        if useFirstCert, let certURL = Bundle.main.url(forResource: "azure-client1-cert", withExtension: "p12"){
            let cred = credential(from: certURL, password: "passcode")
            completionHandler(URLSession.AuthChallengeDisposition.useCredential, cred)
        }else {
            completionHandler(URLSession.AuthChallengeDisposition.cancelAuthenticationChallenge, nil)
        }
    }else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust{
        completionHandler(URLSession.AuthChallengeDisposition.rejectProtectionSpace, nil)
    }else{
        completionHandler(URLSession.AuthChallengeDisposition.performDefaultHandling, nil);
    }
}
swift azure iis
1个回答
0
投票

最后,我得到了微软的回复,如以下博客 - https://blogs.msdn.microsoft.com/waws/2017/04/03/posting-a-large-file-can-fail-if-you-enable-client-certificates/

我刚刚在一个带有124K文件的原型应用中上传了一个成功的证书。所有需要做的就是为请求设置Expect:100-continue标头。

let request = NSMutableURLRequest(url)
request.setValue("100-continue", forHTTPHeaderField: "Expect")

它适用于使用IIS的所有协议。

© www.soinside.com 2019 - 2024. All rights reserved.