Alamofire: 请问:302跳转之后的 url 如何获取啊?

Created on 19 Nov 2016  ·  3Comments  ·  Source: Alamofire/Alamofire

同题。急!!!

question

Most helpful comment

Hi @noear,

When you get redirected, you can get the original URL from the response.request and the redirected URL from the response.response.

let redirectURLString = "https://www.apple.com/"
let urlString = "https://httpbin.org/redirect-to?url=\(redirectURLString)"

Alamofire.request(urlString).response { response in
    let originalURL = response.request?.url
    let redirectURL = response.response?.url
}

Hopefully that helps answer your question. If Google Translate utterly failed me and I didn't answer your question, please translate into English so we can better understand.

Cheers. 🍻

All 3 comments

@noear 人家都看不懂你的问题.

How to get the redirected url?

Hi @noear,

When you get redirected, you can get the original URL from the response.request and the redirected URL from the response.response.

let redirectURLString = "https://www.apple.com/"
let urlString = "https://httpbin.org/redirect-to?url=\(redirectURLString)"

Alamofire.request(urlString).response { response in
    let originalURL = response.request?.url
    let redirectURL = response.response?.url
}

Hopefully that helps answer your question. If Google Translate utterly failed me and I didn't answer your question, please translate into English so we can better understand.

Cheers. 🍻

真是太简单的;很酷!!!

Was this page helpful?
0 / 5 - 0 ratings