“too many HTTP redirects” while using Alamofire Up

2019-03-01 09:39发布

I'm using Alamofire 3 and encountered this:

[Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-1007 "too many HTTP redirects" UserInfo={NSUnderlyingError=0x15eb422d0 {Error Domain=kCFErrorDomainCFNetwork Code=-1007 "(null)"}, NSErrorFailingURLStringKey=URL omitted, NSErrorFailingURLKey= URL omitted, NSLocalizedDescription= too many HTTP redirects}

while calling this method:

upload(.POST, kTaskSubmitImageUrl, multipartFormData: { multipartFormData in
            multipartFormData.appendBodyPart(data: result, name: "uploaded")
            },
            encodingCompletion:{ encodingResult in

                switch encodingResult
                {
                    case .Success(let upload, _, _):
                        upload.responseJSON{
                            responseData in
                            debugPrint(responseData)
                        }
                    case .Failure(let errorStatus) :
                        debugPrint(errorStatus)
                }
            }
        )

anybody know whats going on about it? Should I look at my server?

1条回答
三岁会撩人
2楼-- · 2019-03-01 10:18

it turns out that in iOS 9, there's this App Transport Security (ATS) to enforce best practices in secure connections between an app and its back end. Hence the redirect issues.

by adding Alamofire.Manager.sharedInstance.delegate.taskWillPerformHTTPRedirection = nil

everything works like magic XD

Cheers

Des

查看更多
登录 后发表回答