我有一个字节数组,它是一个消息摘要。我想通过url将它发送到同一服务器中的另一个应用程序。我不想将它转换为字符串并在另一端拉回数组。
任何人都可以帮助我使用servlet吗?
我的代码如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
}
答案 0 :(得分: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();
答案 1 :(得分: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();