81,116
社区成员
发帖
与我相关
我的任务
分享
public void setPost() {
PostMethod post = new PostMethod(
"http://localhost:9999/t/retrieve");
Util des = new Util();
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><request><sid value=\"100006\" /><barcodeid value=\"1325\" /><terminalid value=\"7001\" /></request>";
try {
byte[] s = des.encryptData(xml, "MGI0ZmZ6".getBytes());//将字符串进行DES加密
System.out.println(s.length);//打印出来136
ByteArrayInputStream tInputStringStream = new
ByteArrayInputStream(s);
post.setRequestBody(tInputStringStream);
post.setRequestHeader("Request-Type", "noticeVerify");
post.setRequestHeader("Content-length", "" + s.length);//136
post.setRequestHeader("Content-type", "application/vbs.xml");
HttpClient httpclient = new HttpClient();
int result = httpclient.executeMethod(post);
System.out.println("Response status code: " + result);
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());
post.releaseConnection();
} catch (Exception ex) {
System.out.println(ex);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
StringBuilder sb = null;
try {
BufferedReader br = new BufferedReader(new InputStreamReader((
ServletInputStream) request.getInputStream()));
String line = null;
sb = new StringBuilder();
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
} catch (IOException ex2) {
System.out.println(ex2);
}
String e = sb.toString();
Util des = new Util();
System.out.println(e.getBytes().length);//134
}