HttpURLConnection conn.getRequestProperty return null

http, httpurlconnection, java, web

Solution

Not quite sure what you really want to do. But to see what is posted to the server you would have to post it to your own and read the data you receive there.

If you want to see all the REQUEST headers you could:

for (String header : conn.getRequestProperties().keySet()) {
   if (header != null) {
     for (String value : conn.getRequestProperties().get(header)) {
        System.out.println(header + ":" + value);
      }
   }
}

Or after connecting you can print out the RESPONSE headers:

for (String header : conn.getHeaderFields().keySet()) {
   if (header != null) {
     for (String value : conn.getHeaderFields().get(header)) {
        System.out.println(header + ":" + value);
      }
   }
}

Problem

I'm trying to push some data to an URL (MDS_CS) for a BES when i set some Request Headers in my code, and submit the request, the submited request's header is set to null. here is my code : ``` HttpURLConnection conn =(HttpURLConnection)url.openConnection(); conn.setDoInput(true);//For receiving the confirmation conn.setDoOutput(true);//For sending the data conn.setRequestMethod("POST");//Post the data to the proxy conn.setRequestProperty("X-Rim-Push-ID", pushId); conn.setRequestProperty("Content-Type", "text/html"); conn.setRequestProperty("X-Rim-Push-Title", "-message"); conn.setRequestProperty("X-Rim-Push-Type", "browser-message"); conn.setRequestProperty("X-Rim-Push-Dest-Port", "7874"); //Write the data OutputStream out = conn.getOutputStream(); out.write(data.getBytes()); out.close(); System.out.println(conn.getHeaderField("X-Rim-Push-ID")); ``` the last line return null when i try to retrieve the X-Rim-Push-Title it is NULL only X-Rim-Push-ID which is correctly retrieved, please help me

Original source