分享

Cookie在Get请求和Post请求中的区别

 昵称35402089 2016-07-30

1.使用Get请求

  • 说明如下:

  • 在AServlet中new一个Cookie让客户端保存

  • 在BServlet中显示在AServlet中创建的cookie

    1.1在浏览器中直接输入URL:http://localhost:8080/Demo2/AServlet
    的请求头

GET /Demo2/AServlet HTTP/1.1Host: localhost:8080Connection: keep-aliveAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36Accept-Encoding: gzip, deflate, sdchAccept-Language: zh-CN,zh;q=0.8,en;q=0.6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
1.2在浏览器中直接输入URL:http://localhost:8080/Demo2/BServlet

的请求头

GET /Demo2/servlet/BServlet HTTP/1.1Host: localhost:8080Connection: keep-aliveAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36Accept-Encoding: gzip, deflate, sdchAccept-Language: zh-CN,zh;q=0.8,en;q=0.6*************************************************Cookie: uuid=08ee7eda-9cd9-49dd-8630-7a4d16fd494e*************************************************
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

2.使用Post请求

  • 说明如下:

  • 在index.jsp中先后分别请求AServlet和BServlet

    index.jsp

<body> <form action='/Demo2/AServlet' method='post'> <input type='submit' value='post-AServlet'/> form> <form action='/Demo2/BServlet' method='post'> <input type='submit' value='post-BServlet'/> form> body>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
2.1请求AServlet
POST /Demo2/AServlet HTTP/1.1Host: localhost:8080Connection: keep-aliveContent-Length: 0Cache-Control: max-age=0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Origin: http://localhost:8080Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36Content-Type: application/x-www-form-urlencodedReferer: http://localhost:8080/Demo2/index.jspAccept-Encoding: gzip, deflateAccept-Language: zh-CN,zh;q=0.8,en;q=0.6******************************************************Cookie: JSESSIONID=D4288C7911533D4275DDE31AE33B961C******************************************************
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

2.2请求BServlet

POST /Demo2/BServlet HTTP/1.1Host: localhost:8080Connection: keep-aliveContent-Length: 0Cache-Control: max-age=0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Origin: http://localhost:8080Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36Content-Type: application/x-www-form-urlencodedReferer: http://localhost:8080/Demo2/index.jspAccept-Encoding: gzip, deflateAccept-Language: zh-CN,zh;q=0.8,en;q=0.6********************************************************Cookie: JSESSIONID=D4288C7911533D4275DDE31AE33B961C; uuid=743468ab-c83d-4298-b127-477fa6194140*********************************************************POST /Demo2/BServlet HTTP/1.1Host: localhost:8080Connection: keep-aliveContent-Length: 0Cache-Control: max-age=0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Origin: http://localhost:8080Upgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36Content-Type: application/x-www-form-urlencodedReferer: http://localhost:8080/Demo2/index.jspAccept-Encoding: gzip, deflateAccept-Language: zh-CN,zh;q=0.8,en;q=0.6*****************************************************Cookie: JSESSIONID=D4288C7911533D4275DDE31AE33B961C; uuid=743468ab-c83d-4298-b127-477fa6194140*****************************************************
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

可以发现使用get和post所请求的头的Cookie头不一样,get请求一开始没有cookie头字段而post请求始终有cookie头字段其cookie为JSESSIONID

先把这个问题记着,搞懂了,分析一下~

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约