Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set the referer in the initial request made by SFSafariViewController?

SFSafariViewController is compelling, but has a very simple API that doesn't allow setting any fields on the request it initiates when presented. Are there any clever ways to set the HTTP referer header on requests initiated from SFSafariViewController?

like image 482
Tim Johnsen Avatar asked Aug 27 '15 01:08

Tim Johnsen


People also ask

How do I change http Referer?

If you want to change the referer (url) header that will be sent to the server when a user clicks an anchor or iframe is opened, you can do it without any hacks. Simply do history. replaceState, you will change the url as it will appear in the browser bar and also the referer that will be send to the server.

How is a referrer set?

The Referer header is set by your browser and sent to the server when you request a page. The value of this header is the URL of the previous page that linked to the newly requested page. It is where you came from, essentially.

Does browser always send Referer?

This will not work, because browsers don't treat these pages as normal web resources and thus they do not automatically send the "Referer" header when you submit a form.

What is Referer header in HTTP request?

The Referer HTTP request header contains an absolute or partial address of the page that makes the request. The Referer header allows a server to identify a page where people are visiting it from. This data can be used for analytics, logging, optimized caching, and more.


2 Answers

There is no API for that, unfortunately.

You can check SFSafariViewControllerDelegate page - all of the delegate methods is post-load handlers.

WKWebView and WKNavigationDelegate is one of possible replacements (iOS 8.0+).

like image 81
Andrei Konstantinov Avatar answered Oct 08 '22 22:10

Andrei Konstantinov


The only way I could think to do this would be to bounce the request off of a web service that you control.

Sadly you can't use anything other than http or https URLs, so a local file URL won't work (short of listening on a socket on the device).

like image 30
Frank Schmitt Avatar answered Oct 08 '22 23:10

Frank Schmitt