Java – httpurlconnection conn.getrequestproperty returns null

I'm trying to push some data to the URL of BES (mds_cs) @ h_ 502_ 2 @ when I set some request headers in my code and submit the request, the header for submitting the request is set to null

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"));

Solution

I'm not sure what you really want to do But to see what is published to the server, you must publish it to your own content and read the data you receive there@ H_ 502_ 2 @ if you want to view all request headers, you can:

for (String header : conn.getRequestProperties().keySet()) {
   if (header != null) {
     for (String value : conn.getRequestProperties().get(header)) {
        System.out.println(header + ":" + value);
      }
   }
}
for (String header : conn.getHeaderFields().keySet()) {
   if (header != null) {
     for (String value : conn.getHeaderFields().get(header)) {
        System.out.println(header + ":" + value);
      }
   }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>