0

我有一个字节数组,它是一个消息摘要。我想通过 url 将它发送到同一服务器中的另一个应用程序。我不想将它转换为字符串并拉回另一端的数组。

任何人都可以帮助我使用 servlet 做到这一点吗?

我的代码如下

发送requauset.java

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        byte[] encryptedUserName;               
        String username = request.getParameter("username");     
        RsaEncryption encrypt = new RsaEncryption();
        encryptedUserName     = encrypt.encryptClientMassage(username.getBytes(),pk,md);
        String url = "domain/server/GetRequset?username="+encryptedUserName+"";
        response.sendRedirect(url);
    }

}

GetRequset.java

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //i want to get username to byte array from here.I try with request.getParameter("username") but i returns string


    }
4

2 回答 2

1
URLConnection conn = new URL(URL to send input stream").openConnection();
conn.setDoOutput(true);
OutputStream outs = conn.getOutputStream();
outs.write(pdfBytes);
outs.flush();   
outs.close();

另一方面从请求中获取输入流

request.getInputStream();
于 2013-06-12T05:18:16.970 回答
0
URL url = null;

                url = new URL("Your service URL");

            HttpURLConnection connection = null;

                connection = (HttpURLConnection) url.openConnection();


                connection.setRequestMethod("POST");

            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setInstanceFollowRedirects(false); 
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
            connection.setRequestProperty("charset", "utf-8");
            connection.setRequestProperty("Content-Length", "" + 0);
            connection.setUseCaches (false);
            DataOutputStream wr = null;

                wr = new DataOutputStream(connection.getOutputStream ());

            int code = 0;
            try {
                code = connection.getResponseCode();
                wr.flush();
                wr.close();
            } catch (IOException e) {
                logger.error("Error occured while checking the CPR connection", e);
            }
            connection.disconnect();
于 2013-06-12T07:21:14.033 回答