I searched other topics and there were some answers but I didn't succeed to solve my problem. I have this code and I want to add "Referer" to my http headers. After using setRequestProperty method, I log the results in Logcat but I don't see referer in the output. what am I 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 also have another code which is 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 the first code, I don't see referer in the output and also for the second code, I don't see cookies too. So it seems setRequestProperty is not working! Thanks in advance.
EDIT: I can see headers in the output but not the ones I added via setRequestProperty method. so the if code is working.