Ios 如何从.POST HTTP请求访问重定向的URL响应
我正在尝试连接到一个支付服务器,它应该将我重定向到另一个URL,而不是我代码中的URL 因此,我使用Alamofire(.POST-request)连接到服务器,但我总是输入“太多HTTP重定向”代码=1007的错误案例 我知道服务器应该返回,我需要的是在我的xcode控制台中打印服务器试图重定向到的URL 我尝试使用:Ios 如何从.POST HTTP请求访问重定向的URL响应,ios,swift,alamofire,Ios,Swift,Alamofire,我正在尝试连接到一个支付服务器,它应该将我重定向到另一个URL,而不是我代码中的URL 因此,我使用Alamofire(.POST-request)连接到服务器,但我总是输入“太多HTTP重定向”代码=1007的错误案例 我知道服务器应该返回,我需要的是在我的xcode控制台中打印服务器试图重定向到的URL 我尝试使用: print(response.response?.allHeaderFields) 但在输出中没有帮助,无法访问重定向的URL let urlString = "http:/
print(response.response?.allHeaderFields)
但在输出中没有帮助,无法访问重定向的URL
let urlString = "http://www.gazdev.tk/PHP_VPC_3Party_Order_DO.php"
Alamofire.request(urlString, method: .post, parameters: parameters,encoding: JSONEncoding.default, headers: nil).responseJSON {
response in
switch response.result {
case .success:
print(response.response)
break
case .failure(let error):
print(response.response)
print(error)
}
}
我将此作为打印声明:
加载失败,错误为Domain=NSURLErrorDomain Code=-1007“HTTP重定向太多”
我认为
response.response?.url
是您想要的,例如:
AF.request(“https://httpbin.org/get).responseJSON{response in
debugPrint(“重定向=\(response.response?.url)”)
}