I want my Swift iOS application to fetch the URL it receives via the NSUserActivityTypeBrowsingWeb request.
My email service-provider "wraps" the links (like most of them do), returning a "302 redirect" message. I want to do the initial GET, to get "302 Found" and "Location" header, but I don't need iOS to follow the redirect for me.
I've added the following code:
// Follow the link to trigger click tracking
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
guard let data = data else { return }
print(String(data: data, encoding: .utf8)!)
}
task.resume()
This works, but I don't need to follow the redirect and fetch all of the data (as it can be quite a large web page).
Does iOS provide a way of getting the initial HTTP(S) response without following the redirect? (A bit like omitting the --location flag on CURL).