关于post取数据的问题 希望大家来研究一下

boy_wh520 2010-07-27 01:54:21
客户端post请求

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);
}

}


客户端取数据的时候 是用一个servlet

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


}




问题就是 客户端传输的字节数是136

到服务端取到的数据却是134 丢失2个字节 希望个人朋友帮忙分析一下
...全文
89 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
boy_wh520 2010-07-27
  • 打赏
  • 举报
回复
搞定了 谢谢各位
商科程序员 2010-07-27
  • 打赏
  • 举报
回复
可能是编码问题.
你把字符串编成BASE64试试.
商科程序员 2010-07-27
  • 打赏
  • 举报
回复
你再BASE64一下再发看看还少不少.
可能是编码问题.
sun0322 2010-07-27
  • 打赏
  • 举报
回复
学习。

81,116

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧