Saturday, January 2, 2016

HTTP Protocol

1. http is built based on tcp/ip
2. Hyper Text Transfer Protocol
3. Http 1.0, and 1.1, now normally using 1.1
    http1.0: short time connection, disconnect immediately
    http1.1: longer time connection, 30 seconds

Request Header
GET /test/hello.html HTTP/1.1
Accept: */*
Referer: http://localhost:8080/test/abc.html
Accept-Language: zh-cn
User-Agent: Mozilla/4.0
Accept-Encoding: gzip, deflate
Host: localhost:8080
Connection: Keep-Alive
[empty line]
dataname1=data1
dataname2=data2

  1. Accept: text/html, image/*
  2. Accept-Charset: ISO-8859-1
  3. Accept-Encoding: gzip, compress
  4. Accept-Language: en-us,zh-cn
  5. Host: www.sohu.com:80
  6. If-Modified-Since: Tue, 11 Jul 2000 18:23:51 GMT    //cache time, refresh if there is newer
  7. Referer: http://www.sohu.com/index.jsp //tell host where this request come from, prevent spam
  8. User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
  9. Cookie
  10. Connection: close    // or Keep-Alive
  11. Date: Tue, 11 Jul 2000 18:23:51 GMT


Request Methods:

POST GET HEAD OPTIONS DELETE TRACE PUT


Response Header


  1. HTTP/1.1 200 OK
  2. Location: http://www.baidu.com //tell browser to redirect new url
  3. Server: apache tomcat
  4. Content-Encoding: gzip
  5. Content-Length: 80
  6. Content-Language: zh-cn
  7. Content-Type: text/html; charset=GB2312 //response.setContentType("text/html;charset=GB2312");
  8. Last-Modified: Tue, 11 Jul 2000 18:23:51 GMT
  9. Refresh: 1;url=http://www.baidu.com     //redirect to url after 1 second
    //response.setHeader("Refresh", "5;url=http://www.sohu.com");
  10. Content-Disposition: attachment; filename=aaa.zip
    //tell browser that there is file to download
    //response.setHeader("Content-Disposition","attachment; filename=aaa.zip");
  11. Transfer-Encoding: chunked     //checksum verified
  12. Set-Cookie:SS=Q0=5Lb_nQ; path=/search   //to be introduced
  13. Expires: -1                               //tell browser(IE) how to cache data
  14. Cache-Control: no-cache         //tell browser(FireFox) how to cache data
  15. Pragma: no-cache                    //tell browser(some browser) how to cache data
    //response.setDateHeader("Expires",-1); //or value to System.currentTimeMillis()+1*1000;
    //response.setHeader("Cache-Control","no-cache");
    //response.setHeader("Pragma","no-cache");
  16. Connection: close/Keep-Alive
  17. Date: Tue, 11 Jul 2000 18:23:51 GMT


State Code

  • 200 normal
  • 302 server request browser redirect to another resource
    response.sendRedirect("anotherPage")
    // or response.setStatus(302); response.setHeader("Location","anotherPage");
  • 404 not found
  • 500 server error
    throw new RuntimeException();


No comments:

Post a Comment