1.表單<form>
2.fsockopen();
3.jquery
語法:
$.post ($.ajax的簡寫)
示例代碼:
<!DOCTYPE html> <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $.post("./index.php", { name:"Donald Duck", city:"Duckburg" },function(data){$("button").html(data)}); }); }); </script> </head> <body> <button>向頁面發送 HTTP POST 請求,並獲得返回的結果</button> </body> </html> <?php file_put_contents("1.txt", json_encode($_REQUEST),FILE_APPEND); echo "12222222".json_encode($_REQUEST); ?>
4.$HTTP_RAW_POST_DATA
$_POST:通過 HTTP POST 方法傳遞的變量組成的數組。是自動全局變量。 $GLOBALS['HTTP_RAW_POST_DATA'] :總是產生 $HTTP_RAW_POST_DATA 變量包含有原始的 POST 數據。此變量僅在碰到未識別 MIME 類型的數據時產生。$HTTP_RAW_POST_DATA 對於 enctype="multipart/form-data" 表單數據不可用。 也就是說基本上$GLOBALS['HTTP_RAW_POST_DATA'] 和 $_POST是一樣的。 但是如果post過來的數據不是PHP能夠識別的,你可以用 $GLOBALS['HTTP_RAW_POST_DATA']來接收,比如 text/xml 或者 soap 等等。 補充說明:PHP默認識別的數據類型是application/x-www.form-urlencoded標准的數據類型。
***********************************************************************************
這是手冊里寫的
總是產生變量包含有原始的 POST 數據。否則,此變量僅在碰到未識別 MIME 類型的數據時產生。不過,訪問原始 POST 數據的更好方法是 php://input。$HTTP_RAW_POST_DATA 對於 enctype="multipart/form-data" 表單數據不可用。
問題: $HTTP_RAW_POST_DATA == $_POST 嗎?
照手冊所寫 ,答案應該就為否。 假如不一樣的話,他們的區別是什么呢?
我知道答案了,如下:
The RAW / uninterpreted HTTP POst information can be accessed with: $GLOBALS['HTTP_RAW_POST_DATA'] This is useful in cases where the post Content-Type is not something PHP understands (such as text/xml).
也就是說,基本上$GLOBALS['HTTP_RAW_POST_DATA'] 和 $_POST是一樣的。但是如果post過來的數據不是PHP能夠識別的,你可以用 $GLOBALS['HTTP_RAW_POST_DATA']來接收,比如 text/xml 或者 soap 等等。
PHP默認識別的數據類型是application/x-www.form-urlencoded標准的數據類型
用Content-Type=text/xml 類型,提交一個xml文檔內容給了php server,要怎么獲得這個POST數據。
The RAW / uninterpreted HTTP POST information can be accessed with: $GLOBALS['HTTP_RAW_POST_DATA'] This is useful in cases where the post Content-Type is not something PHP understands (such as text/xml).
由於PHP默認只識別application/x-www.form-urlencoded標准的數據類型,因此,對型如text/xml的內容無法解析為$_POST數組,故保留原型,交給$GLOBALS['HTTP_RAW_POST_DATA'] 來接收。
另外還有一項 php://input 也可以實現此這個功能
php://input 允許讀取 POST 的原始數據。和 $HTTP_RAW_POST_DATA 比起來,它給內存帶來的壓力較小,並且不需要任何特殊的 php.ini 設置。php://input 不能用於 enctype="multipart/form-data"。
應用
a.htm ------------------ <form action="post.php" method="post"> <input type="text" name="user"> <input type="password" name="password"> <input type="submit"> </form>
post.php ---------------------------- <? echo file_get_contents("php://input"); ?>