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

1.使用Get请求

  • 说明如下:

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

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

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

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

的请求头

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

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>
2.1请求AServlet
POST /Demo2/AServlet HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 0
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: http://localhost:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Referer: http://localhost:8080/Demo2/index.jsp
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
******************************************************
Cookie: JSESSIONID=D4288C7911533D4275DDE31AE33B961C
******************************************************

2.2请求BServlet

POST /Demo2/BServlet HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 0
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: http://localhost:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Referer: http://localhost:8080/Demo2/index.jsp
Accept-Encoding: gzip, deflate
Accept-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.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 0
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: http://localhost:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Referer: http://localhost:8080/Demo2/index.jsp
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
*****************************************************
Cookie: JSESSIONID=D4288C7911533D4275DDE31AE33B961C; uuid=743468ab-c83d-4298-b127-477fa6194140
***************************************************** 

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

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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值