0

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

Community
  • 1
  • 1
user984003
  • 28,050
  • 64
  • 189
  • 285
  • your question is not clear. you want to send http headers to a webview along with the url you pass? – developer82 Jan 22 '16 at 15:48
  • Yes. The website that is linked to should be able to see that the traffic is coming from my website. Different URLs are opened in different webviews, which is why it's not just a normal link within a webview ( which would pass the referer naturally). – user984003 Jan 22 '16 at 16:56
  • and you pass this data in the request header and not the query string? – developer82 Jan 23 '16 at 05:39

2 Answers2

1

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

Community
  • 1
  • 1
tzmartin
  • 96
  • 7
0

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.

miga
  • 3,997
  • 13
  • 45