java - Android HttpUrlConnection passing header params -



java - Android HttpUrlConnection passing header params -

i searched other topics , there answers didn't succeed solve problem. have code , want add together "referer" http headers. after using setrequestproperty method, log results in logcat don't see referer in output. doing wrong?

url url = new url(uri); httpurlconnection con = (httpurlconnection) url.openconnection(); con.setrequestproperty("referer", "http://www.example.com"); for(int i=0;con.getheaderfieldkey(i)!=null;i++){ string headername = con.getheaderfieldkey(i); string headervalue = con.getheaderfield(i); log.d("header", headername + ": " + headervalue); }

i have code not working either:

url url = new url(uri); httpurlconnection con = (httpurlconnection) url.openconnection(); string irnic = cookies.get("irnic"); string routeid = cookies.get("routeid"); string mycookies = "irnic="+irnic+"; routeid="+routeid; con.setrequestproperty("cookie", mycookies); for(int i=0;con.getheaderfieldkey(i)!=null;i++){ string headername = con.getheaderfieldkey(i); string headervalue = con.getheaderfield(i); log.d("header", headername + ": " + headervalue); }

for first code, don't see referer in output , sec code, don't see cookies too. seems setrequestproperty not working! in advance.

edit: can see headers in output not ones added via setrequestproperty method. if code working.

from docs:

getheaderfields

returns unmodifiable map of response-header fields , values

setrequestproperty

sets value of specified request header field.

request not same response. that's why headers different. request have right headers using setrequestproperty

java android http header httpurlconnection

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -