Request.java 738 B

1234567891011121314151617181920212223242526272829303132
  1. package cn.hhj.bio.tomcat.http;
  2. import java.io.InputStream;
  3. public class Request {
  4. private String method;
  5. private String url;
  6. public Request(InputStream in)throws Exception{
  7. //拿到HTTP协议内容
  8. String content = "";
  9. byte[] buffer=new byte[1024];
  10. int len = 0;
  11. if ((len = in.read(buffer)) > 0) {
  12. content = new String(buffer,0,len);
  13. }
  14. String line = content.split("\\n")[0];
  15. String [] arr = line.split("\\s");
  16. this.method = arr[0];
  17. this.url = arr[1].split("\\?")[0];
  18. System.err.println(content);
  19. }
  20. public String getUrl() {
  21. return url;
  22. }
  23. public String getMethod() {
  24. return method;
  25. }
  26. }