0

I have a byte array that is a Message digest. And i want send it to another appliction in same server via url.I don't want to convert it to string and pull back the array on the other end.

Can any one help me do this using servlet?

my code like bellow

Sendrequauset.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


    }
1

2 Answers 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();

on other side get that input stream from request

request.getInputStream();
Sign up to request clarification or add additional context in comments.

1 Comment

can you give me example pls ?
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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.