用socket类实现http服务器时如何读取Post的数据
用serversoceket类和socket类实现了一个简单的http服务器。
关键代码如下:
1 PrintStream outstream=new PrintStream(client.getOutputStream());
2 DataInputStream instream=new DataInputStream(client.getInputStream());
3 String inline=instream.readLine(); // 读取Web浏览器提交的请求信息
4 System.out.println(inline);
5 while(inline!=null){
6 inline=instream.readLine();
7 System.out.println(inline);
8 }
其中client是ServerSocket类accept方法返回的socket类实例,负责与客户端通讯。
现在的问题是,上面的代码只能读取http请求的头部信息,不能读取头部以后的post数据。
程序会在第6行readLine()调用处堵塞。
请问,有什么办法能让程序读取post的数据。
谢谢了