I am simply making a GET
request to a Rest API using HttpURLConnection
.
I need to add some custom headers but I am getting null
wh
It is a good idea to send
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("CustomHeader", token);
instead of
// Set Headers
conn.setRequestProperty("CustomHeader", "someValue");
conn.setRequestProperty("accept", "application/json");
Both the type value and header should be changed. it works in my case.
The conn.getHeaderField("CustomHeader")
returns the response header not the request one.
To return the request header use: conn.getRequestProperty("CustomHeader")