java - How set Http setHeader? -
i use below code:
class test extends asynctask < string, void, string > { @override protected string doinbackground(string...urls) { string response = ""; (string url: urls) { defaulthttpclient client = new defaulthttpclient(); httpget httpget = new httpget(url); try { httpresponse execute = client.execute(httpget); inputstream content = execute.getentity().getcontent(); bufferedreader buffer = new bufferedreader( new inputstreamreader(content)); string s = ""; while ((s = buffer.readline()) != null) { response += s; } } catch (exception e) { e.printstacktrace(); } } return response; } @override protected void onpostexecute(string result) { testlogin.textview.settext(result); } }
what changes should modified in above code set header? want access webpage jsonobjcets "http://apimobile.dev2.rtbtracker.com/api/v2/users"
use setheader()
method on httpget
httpget.setheader("header-name", "header value");
in code :
defaulthttpclient client = new defaulthttpclient(); httpget httpget = new httpget(url); //setting header httpget.setheader("header-name", "header value"); try { httpresponse execute = client.execute(httpget); //process } catch (exception e) { e.printstacktrace(); }
Comments
Post a Comment