1、當(dāng)Coentent-Type = application/x-www-data-urlencoded 時(shí)
1.1 $_POST的值為數(shù)組 數(shù)組的值為發(fā)過來的參數(shù);
1.2 file_get_contents("php://input");的值為字符串"jjjj=asdjhkjashd&asd=asd" 并且這個(gè)字符串不符合json的規(guī)范 無法用json_decode($str, true); 轉(zhuǎn)化成對(duì)象
2、當(dāng)Coentent-Type = multipart/form-data 時(shí)
1.1$_POST的值為數(shù)組 數(shù)組的值為發(fā)過來的參數(shù);
1.2 file_get_contents("php://input");無法獲取到數(shù)據(jù)
3、當(dāng)Coentent-Type = application/json時(shí)
1.1 $_POST無法獲取到數(shù)據(jù);
1.2 file_get_contents("php://input");的值為json格式的字符串{"ceshi":"ceshi","ooooo":"OK","jjjjj":{"jjjj":"asdas","asdasd":"asdasd"},"array":["asdasd","asdasd"]} 可以用json_decode($str, true); 轉(zhuǎn)化成對(duì)象
4、總結(jié)
0、php://input數(shù)據(jù)總是跟$HTTP_RAW_POST_DATA相同,但是php://input比$HTTP_RAW_POST_DATA更湊效,且不需要特殊設(shè)置php.ini
1、Coentent-Type僅在取值為application/x-www-data-urlencoded和multipart/form-data兩種情況下,PHP才會(huì)將http請(qǐng)求數(shù)據(jù)包中相應(yīng)的數(shù)據(jù)填入全局變量$_POST
2、只有Coentent-Type為multipart/form-data的時(shí)候,PHP不會(huì)將http請(qǐng)求數(shù)據(jù)包中的相應(yīng)數(shù)據(jù)填入php://input,否則其它情況都會(huì)。填入的長(zhǎng)度,由Coentent-Length指定。
3、php://input 與$HTTP_RAW_POST_DATA讀取的數(shù)據(jù)是一樣的,都只讀取Content-Type不為multipart/form-data的數(shù)據(jù)。
4、php://input 可以讀取http entity body中指定長(zhǎng)度的值,由Content-Length指定長(zhǎng)度,不管是POST方式或者GET方法提交過來的數(shù)據(jù)。但是,一般GET方法提交數(shù)據(jù) 時(shí),http request entity body部分都為空。
5、php://input 數(shù)據(jù)總是跟$HTTP_RAW_POST_DATA相同,但是php://input比$HTTP_RAW_POST_DATA更湊效,且不需要特殊設(shè)置php.ini