HttpURLConnection conn.getRequestProperty return null

为君一笑 提交于 2019-12-04 06:56:08

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

I would suggest using Apache HttpClient

final HttpClient client = new HttpClient();
final PostMethod method = new PostMethod(uri);
method.addRequestHeader("X-Rim-Push-Title", "-message");
client.executeMethod(method);
String responseBody = method.getResponseBodyAsString();
Header[] headers = method.getResponseHeaders();

HttpClient is a much more powerful way of dealing with HTTP than HttpURLConnection.

dzgeek

When I check my headers submitted and the inputstream of request, I get the 200 ok status, but nothing is sent to device

from server: 200 | OK


=======REQUEST===============
request header:X-Rim-Push-ID:pushID:1342694818991
request header:Host:win-uhgr7vs88uz.assabb.com:8080
request header:Content-Length:19
request header:X-Rim-Push-Title:-message
request header:User-Agent:Java/1.6.0_18
request header:POST /push?DESTINATION=bestest%40assa-associates.com&PORT=7874&REQUESTURI=/ HTTP/1.1:null
request header:Content-Type:text/html
request header:Accept:text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
request header:Connection:keep-alive
request header:X-Rim-Push-Dest-Port:7874
request header:X-Rim-Push-Type:browser-message
======Response===============
response header:Date:Thu, 19 Jul 2012 10:47:10 GMT
response header:Content-Length:0
response header:X-RIM-Push-ID:pushID:1342694818991
response header:Via:MDS_5.0.3.26
response header:x-rim-multidest-push-supported:true
response header:Server:Apache-Coyote/1.1
response header:x-rim-push-persisted:fals
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!