How to modify HTTP request headers from an Android app? -



How to modify HTTP request headers from an Android app? -

is there way me capture http requests beingness sent app, , modify headers before sent? want modify referer header server requests sent thinks if coming web browser instead of mobile application. give thanks you!

update: give more context, planning port chrome extension instant music android app using phonegap. youtube videos allowed on pc not allowed on mobile , suspect that's because youtube player embedded within android app doesn't have referrer header. trying find solution problem can play such videos on mobile too.

youtube detects user browser's agent string contains info browser. if utilize webview show youtube video instead, possible set webview's agent string. can find agent strings of different browsers on internet. found here: agent strings.

here's how play bob marley's song not allowed on mobile phones impersonating firefox browser:

package com.my.myapplication; import android.app.activity; import android.os.bundle; import android.webkit.webview; import android.webkit.webviewclient; import android.widget.toast; public class myactivity extends activity { private webview mwebview ; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mwebview = new webview(this); // enable javascript mwebview.getsettings().setjavascriptenabled(true); // impersonate mozzila browser mwebview.getsettings().setuseragentstring("mozilla/5.0 (windows nt 6.2; win64; x64; rv:21.0.0) gecko/20121011 firefox/21.0.0"); final activity activity = this; mwebview.setwebviewclient(new webviewclient() { public void onreceivederror(webview view, int errorcode, string description, string failingurl) { toast.maketext(activity, description, toast.length_short).show(); } }); mwebview .loadurl("http://youtube.com/watch?v=x59ks2aorgm"); setcontentview(mwebview); } }

edit:

you need give permission activity utilize internet, adding line androidmanifest.xml:

<uses-permission android:name="android.permission.internet" />

android http

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -