HTTP協議規範沒有對URL長度進行限制,也沒有限制消息主體的大小,因此從理論上講,GET、POST是沒有大小限制的。那又爲何在使用過程當中會有大小限制呢??ajax
GET方式數據長度限制:瀏覽器
POST方式數據長度限制:安全
HTTP協議是以ASCII碼傳輸,創建在TCP/IP協議之上的應用層規範。規範把HTTP 請求分爲三個部分:狀態行、請求頭、消息主體。POST請求發送的數據是放在消息主體中,這是遵循HTTP協議的規範格式,而GET是將發送的數據直接拼接在URL的後面,也就是在狀態行中。很明顯,POST方式比GET方式安全服務器
POST方式:app
狀態行:
Request URL:http://crm.piao.qunar.com
Request Method:POST
請求頭:
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:zh-CN,zh;q=0.8,en;q=0.6
Cache-Control:no-cache
Connection:keep-alive
Content-Length:190
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:QN1=wKgZEVYbR4wc9UPaYgXcAg==; QN99=3984;
Host:crm.piao.qunar.com:8080
Origin:http://crm.piao.qunar.com:8080
Pragma:no-cache
Referer:http://crm.piao.qunar.com:8080/merchantPage/group-supplier
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36
X-Requested-With:XMLHttpRequest
消息主體:
data=1
GET方式:post
狀態行:
Request URL:http://crm.piao.qunar.com?data=1
Request Method:GET
請求頭:
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:zh-CN,zh;q=0.8,en;q=0.6
Cache-Control:no-cache
Connection:keep-alive
Content-Length:190
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:QN1=wKgZEVYbR4wc9UPaYgXcAg==; QN99=3984;
Host:crm.piao.qunar.com:8080
Origin:http://crm.piao.qunar.com:8080
Pragma:no-cache
Referer:http://crm.piao.qunar.com:8080/merchantPage/group-supplier
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36
X-Requested-With:XMLHttpRequest
消息主體:
POST請求須要設置:enctype=application/x-www-form-urlencoded編碼
文件上傳須要設置:enctype=multipart/form-dataurl
使用jQuery的GET、POST方式傳輸數據都有可能未通過utf-8編碼,jQuery.param方法是將鍵值對轉化爲utf-8編碼的方法。當使用jQuery的GET或者POST方式發送數據時,若是data類型不是string,那麼會對data進行utf-8編碼,能夠看下面的jQuery源碼:spa
if ( s.data && s.processData && typeof s.data !== "string" ) { s.data = jQuery.param( s.data, s.traditional ); }
爲了確保傳輸的數據爲utf-8編碼,怎麼辦??code
$.ajax/$.get/$.post
方法時,data屬性值爲一個對象