Make sure you are getting the successful response before you try to fetch the headers. This is how you can check for your response:
int status = conn.getResponseCode();
if (status == HttpURLConnection.HTTP_OK) {
String header = conn.getHeaderField("MyHeader");
}
Also make sure the Servlet response is not a redirect response, if redirected all the session information, including headers will be lost.