Hi,
I have the following situation, where the same piece of code, returns the expected header value, i.e. "text/html;charset=UTF-8" when run against one URL and returns another header value, i.e. "text/html; charset=ISO-8859-1" when run against a different URL. The relevant sections of my code are -
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setInstanceFollowRedirects(false);
conn.connect();
for (int i=0; ; i++) {
String headerName = conn.getHeaderFieldKey(i);
String headerValue = conn.getHeaderField(i);
System.out.println("headerName: " + headerName + "; headerValue: " + headerValue);
if (headerName == null && headerValue == null) {
break;
}
}
I need the value of the "Content-Type" headerName to be set to "text/html;charset=UTF-8", which is true for one URL automatically, but not for the other. The URLs are internal so they won't be relevant if I post here - but they are essentially the same.
I have tried to change the value associated with the "Content-Type" headerName as follows -
conn.setRequestProperty ("Content-Type", "application/xml;charset=UTF-8");
But that has no effect at all.
Am I missing something subtle here, or may be I am trying to do it the wrong way? Please help!