码迷,mamicode.com
首页 > Web开发 > 详细

Http协议中Get 和 Post的发送内容

时间:2014-11-20 12:17:02      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   ar   color   os   使用   sp   for   

遇到这个问题主要原因是在录入JMeter脚本时,原有的HttpSample无法达到请求RequestBody的目的,不得已查看了一些Http协议的简单介绍,最终通过Raw Http插件实现。

Http请求

#一行,描述请求方法、URL、htto协议等信息
<request-line>
#请求头信息
<headers>
<CRLF>

#request body。<headers>使用/r/n占用一行来标记结束
[<request-body><CRLF>]

几点重要备注:

  • request-line中的url一定是使用application/x-www-form-urlencoded编码的,这个与请求方法无关。
  • <headers>Content-Type指明了request body的编码方式。
  • <headers>Content-Length指明了request body的长度,该长度务必等于request-body真正的字符数。少于会导致request-body的确实,多于服务器会等待知道超时才返回已读取的数据(功能没影响,但效率显然差)。


Get请求

GET /hello/index.html HTTP/1.1 
#【↑】request line
#【↓】request headers
Accept: */*
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
Host: localhost:8000
#发送完关闭连接 or 等待
Connection: Keep-Alive
Cookie: JSESSIONID=BBBA54D519F7A320A54211F0107F5EA6

get请求是不存在request body的。

Post请求

#url的部分仍然是urlencoded
POST /hello/checkUser.html?opt=xxx HTTP/1.1
Referer: http://localhost:8000/hello/index.html
Accept: */*
Accept-Language: zh-cn
#纯文本的编码:不编码
Content-Type: text/plain
Accept-Encoding: gzip, deflate
Host: localhost:8000
Content-Length: 20
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=BBBA54D519F7A320A54211F0107F5EA6

#【↑】/r/n
#【↓】request body
12345678901234567890




Http协议中Get 和 Post的发送内容

标签:style   http   io   ar   color   os   使用   sp   for   

原文地址:http://my.oschina.net/pangyangyang/blog/346667

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!