Reputation: 29589
I currently use this
mywebview.setUrl(the_url);
to load a URL.
Can I, instead, load it in such as way as to include a referer in the http header?
EDIT: The reason for this is that the linked-to website should be able to see where the traffic is coming from even if the URL is loaded into a different webview than the one that contained the link. (I use multiple WebViews to create a tab UI.)
Edit: The xcode equivalent seems to be this, although I'm not sure if this is also loading it into a new webview: Specifying HTTP referer in embedded UIWebView
Upvotes: 0
Views: 948
Reputation: 4055
I've looked at the Android Webview header (php getallheaders()
) and there is x-requested-with: com.app.id
So in you page you could check for that value and know at least that it was visited by the app with the bundle identifier. Otherwise you could attach a get parameter to the url ?mobile
and count this.
I'm trying to add a patch to the Android SDK and add a setHeader() method. The loadUrl() call is at: https://github.com/appcelerator/titanium_mobile/blob/bc85170157d3bebc5de1d61a9fe6e34bce84a8c9/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiUIWebView.java#L462
If you change it according to @tzmartin
extraHeaders.put("Referer", "http://www.referer.tld/login.html");
getWebView().loadUrl(finalUrl, extraHeaders);
then it already works but its hard coded.
Upvotes: 0
Reputation: 96
It appears defining custom headers for WebViews is not available yet. You can watch ticket TIMOB-17467 to view updates.
It appears you will need a native module.
A quick check for iOS..
Perhaps you could extend these.
Android appears to be easier to implement, (but still not available in Titanium SDK), via extraHeaders
: Read more: https://stackoverflow.com/a/5342527
Upvotes: 1