测试页面
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name="form1" method="post" action="http://localhost:5001/">
    <input type="text" name="textfield">
    <input type="text" name="textfield2">
    <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>服务器端监听的5001端口,当页面表单提交的时候,得到一个socket连接,得到的socket输入流如下:
POST / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
Host: localhost:5001
Content-Length: 42
Connection: Keep-Alive
Cache-Control: no-cache我怎么看不到页面表单的数据啊?

解决方案 »

  1.   

    如果没有记错,POST的数据在不放在HTTP的数据头里的,而是放在HTTP的数据体里,从那里就可以取到的,不过如果用ASP、JSP、PHP之类的语言,服务器本身就已经帮你解出来了。
      

  2.   

    数据体怎么得到啊,我的读取socket输入流的代码是这样的,有没有问题?
    BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    StringBuffer sb = new StringBuffer();
    String line = br.readLine();
    while (true)
    {
      sb.append(line+"\n");
      if(line.equals(""))
        break;
      line = br.readLine();
    }
      

  3.   

    if(line.equals(""))
        break;
    这个有问题:while(br.readLine()==null).......
      

  4.   

    post是放在数据体了,while(br.readLine()==null).......
      

  5.   

    解决了,用readLine()方法无论是==null还是equals("")我都不能得到在数据体。如下方法可以
    int i = 0;
    while (br.ready() && (i = br.read()) != -1)
    {
      sb.append( (char) i);
    }
    不知用readLine()方法该怎么写?大家讨论下啊
      

  6.   

    可以把表但获取的数据块化!
    表单是string上传,
    string str ;
    str.getbytes[];
    通过byte在socket上传!
      

  7.   

    结贴了,暂时就用read方法了,哪位用readLine实现了的请联系我MSN:[email protected]