博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Http请求的构成
阅读量:4679 次
发布时间:2019-06-09

本文共 2028 字,大约阅读时间需要 6 分钟。

一、http请求的格式:

<request line>       //request type,http version, resource requested

<headers>              //additional infomation server site used

<blank line>            //

<request body>      //add any info here

HTTP定义了与服务器交互的方法,get 和 post。(还有put、delete)用于编码和传递变量名/变量值对,并使用相关的语义

get,以urlencoding编码,以查询字符串的方式传递参数。 server site:Request.QueryString[], length limited 1K,  security issue

post,也以url编码,但参数放在http请求内部、 server site: Request.Form[], no length limited,  no issue about security

二、Get请求的实例 

GET /cgi-bin/tech/method.cgi?txtGET=TestGetMethod HTTP/1.1     //request line

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Referer:
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Host: localhost:8080
Connection: Keep-Alive                               //headers end

发出请求的html代码:

<form action="http://localhost:8080/cgi-bin/tech/method.cgi" method="GET"> //method为get时,浏览器会忽略url?后面的内容

<input type="text" size="10" value="TestGetMethod" name="txtGET">
<input type=submit value="GET方式">
</form>

 浏览器会自动将各表单字段附加在request line中的url后面。客户端的浏览器会缓存他。

三、Post请求的实例

POST /cgi-bin/tech/method.cgi HTTP/1.1                           //request line

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-             //headers begin
powerpoint, application/vnd.ms-excel, application/msword, */*
Referer:
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Host: localhost:8080
Content-Length: 22
Connection: Keep-Alive                                                            //headers end

txtPOST=TestPOSTMethod                                         //body line

发送请求的代码

<form action="http://localhost:8080/cgi-bin/tech/method.cgi" method="POST">

<input type="text" size="10" value="TestPOSTMethod" name="txtPOST">
<input type=submit value="POST方式">
</form>

浏览器会把各表单元素及数据作为http body内容发送给后台。

常见的还有post/get 混发。其实,method=“POST”,只是url后面加了"?parameterName=parameterValue"

转载于:https://www.cnblogs.com/zzq417/archive/2012/08/31/httpProtocal_request.html

你可能感兴趣的文章
Git Day02,工作区,暂存区,回退,删除文件
查看>>
Windows Phone 7 Coding4Fun控件简介
查看>>
Nginx 常用命令总结
查看>>
hall wrong behavior
查看>>
Collection集合
查看>>
【C++】const在不同位置修饰指针变量
查看>>
github新项目挂历模式
查看>>
编写jquery插件
查看>>
敏捷开发笔记
查看>>
学前班
查看>>
关于自关联1
查看>>
hdu-1814(2-sat)
查看>>
谷歌浏览器,添加默认搜索引擎的搜索地址
查看>>
数据结构化与保存
查看>>
为什么需要Docker?
查看>>
国内5家云服务厂商 HTTPS 安全性测试横向对比
查看>>
how to control project
查看>>
转 python新手容易犯的6个错误
查看>>
第四节 -- 列表
查看>>
决策树
查看>>