小编dzg*_*eek的帖子

HttpURLConnection conn.getRequestProperty返回null

我正在尝试将一些数据推送到BES的URL(MDS_CS)

当我在我的代码中设置一些请求标头并提交请求时,提交请求的标头设置为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"));
Run Code Online (Sandbox Code Playgroud)

当我尝试检索X-Rim-Push-Title时,最后一行返回null 只有正确检索的X-Rim-Push-IDNULL

请帮我

java http httpurlconnection web

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

http ×1

httpurlconnection ×1

java ×1

web ×1