HttpURLConnection conn.getRequestProperty返回null [英] HttpURLConnection conn.getRequestProperty return null
问题描述
当我在代码中设置一些请求标头并提交请求时,我正在尝试将一些数据推送到URL(MDS_CS)以获取BES
I'm trying to push some data to an URL (MDS_CS) for a BES
提交请求的标题设置为 null 。
when i set some Request Headers in my code, and submit the request, the submited request's header 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"));
当我尝试检索 X-Rim-Push-Title时,最后一行返回null NULL
只有 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,
请帮帮我
推荐答案
不太确定你真正想做什么。但要查看发布到服务器的内容,您必须将其发布到您自己的内容并阅读您在那里收到的数据。
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.
如果您想查看所有REQUEST标题你可以:
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);
}
}
}
或者在连接后你可以打印out RESPONSE标题:
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);
}
}
}
这篇关于HttpURLConnection conn.getRequestProperty返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!