分类 WEB开发 下的文章

HTTP Methods: GET vs. POST



The two most used HTTP methods are: GET and POST.


<h4>What is HTTP?</h4>

The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers.

HTTP works as a request-response protocol between a client and server.

A web browser may be the client, and an application on a computer that hosts a web site may be the server.

Example: A client (browser) submits an HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and may also contain the requested content.


<h4>Two HTTP Request Methods: GET and POST</h4>

Two commonly used methods for a request-response between a client and server are: GET and POST.

<h5>GET</h5>

Requests data from a specified resource

<h5>POST</h5>

Submits data to be processed to a specified resource

<h4>The GET Method</h4>
Note that query strings (name/value pairs) is sent in the URL of a GET request:

/test/demo_form.asp?name1=value1&name2=value2

<h5>Some other notes on GET requests:</h5>
<h5>GET</h5>

requests can be cached

requests remain in the browser history

requests can be bookmarked

requests should never be used when dealing with sensitive data

requests have length restrictions

requests should be used only to retrieve data

<h4>The POST Method</h4>
Note that query strings (name/value pairs) is sent in the HTTP message body of a POST request:

POST /test/demo_form.asp HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2

<h5>Some other notes on POST requests:</h5>
<h5>POST</h5>

requests are never cached

requests do not remain in the browser history

requests cannot be bookmarked

requests requests have no restrictions on data length

<h4>Compare GET vs. POST</h4>
The following table compares the two HTTP methods: GET and POST.

GET POST
BACK button/Reload Harmless Data will be re-submitted (the browser should alert the user that the data are about to be re-submitted)
Bookmarked Can be bookmarked Cannot be bookmarked
Cached Can be cached Not cached
Encoding type application/x-www-form-urlencoded application/x-www-form-urlencoded or multipart/form-data. Use multipart encoding for binary data
History Parameters remain in browser history Parameters are not saved in browser history
Restrictions on data length Yes, when sending data, the GET method adds the data to the URL; and the length of a URL is limited (maximum URL length is 2048 characters) No restrictions
Restrictions on data type Only ASCII characters allowed No restrictions. Binary data is also allowed
Security GET is less secure compared to POST because data sent is part of the URL Never use GET when sending passwords or other sensitive information! POST is a little safer than GET because the parameters are not stored in browser history or in web server logs
Visibility Data is visible to everyone in the URL Data is not displayed in the URL

Web性能测试中的几个概念(转)

每秒查询率QPS:对一个特定的查询服务器在规定时间内所处理流量多少的衡量标准,即每秒请求数,即最大吞吐能力。

并发数:并发数和QPS是不同的概念,一般说QPS会说多少并发用户下QPS,当QPS相同时,并发用户数越大,网站并发处理能力越好。当并发用户数过大时,会造成进程(线程)频繁切换,反正真正用于处理请求的时间变少,每秒能够处理的请求数反而变少,同时用户的请求等待时间也会变大。 找到最佳线程数能够让web系统更稳定,效率更高。

通过QPS和pv计算部署服务器台数:
单台服务器每天PV计算
公式1:每天总PV = QPS 3600 6
公式2:每天总PV = QPS 3600 8
服务器计算
服务器数量 = ceil( 每天总PV / 单台服务器每天总PV )
峰值QPS和机器计算公式
原理:每天80%的访问集中在20%的时间里,这20%时间叫做峰值时间
公式:( 总PV数 80% ) / ( 每天秒数 20% ) = 峰值时间每秒请求数(QPS)
机器:峰值时间每秒QPS / 单台机器的QPS = 需要的机器
问:每天300w PV 的在单台机器上,这台机器需要多少QPS?
答:( 3000000 0.8 ) / (86400 0.2 ) = 139 (QPS)
问:如果一台机器的QPS是58,需要几台机器来支持?
答:139 / 58 = 3

/bin/rm: argument list too long 的解决方法

今天发现var目录又满了,进去用 du -smh * | sort -n一看,发现 /var/spool/mqueue 占的空间很大,从名字上来看,这个目录是存放系统邮件队列的,为什么队列里堆积了这么多的邮件呢?不清楚,没办法,直接删吧,rm -rf *结果报错了,bash: /bin/rm: Argument list too long,从字面意思上看也知道是参数列表过长,其实就是文件夹里的文件太多了,不能一下子删除,官方的解释是:因为 Linux 内核中所有 exec 系函数(execl, execlp, execle 等)最终调用的都是 execve() , 而execve 是通过一块 128k 的内存空间来保存用以传递给新进程的命令参数和环境变量。当像 rm 这些命令产生的命令行参数超过 128k 的时候, Linux kernel 就报 E2BIG 错误了。

解决方法是:用 find 命令先找出希望删除的文件名再用管道批次传递给 rm 去删除。比如要删除 sendmail 堆积起来的mqueue 目录下的文件:
find /var/spool/mqueue/ -type f -name '*' -print0 | xargs -0 rm
(-0 参数防止文件名中有空格导致被 rm 认作是两个不同的文件。)

又学到了一招。