php 5.4.12
我使用以下.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /cap.php [L]
这是cap.php文件
var_dump($_SERVER['REQUEST_METHOD']);
var_dump($_POST);
die;
结果是
string 'POST' (length=4)
array (size=0)
empty
即。 $ _POST为空,为什么?
这是请求(取自chrome dev工具)
Remote Address:[::1]:6646
Request URL:http://localhost:6646/xa/dealcontent/v2/GetDeals?nocache=1448276132472
Request Method:POST
Status Code:200 OK
Response Headers
view source
Connection:Keep-Alive
Content-Type:application/amazonui-streaming-json
Date:Mon, 23 Nov 2015 10:55:32 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.4.4 (Win64) PHP/5.4.12
Transfer-Encoding:chunked
X-Powered-By:PHP/5.4.12
Request Headers
view source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,he;q=0.6
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:362
Content-Type:application/x-www-form-urlencoded
Cookie:_hjUserId=6f6e7a4c-d589-3e2f-8fbd-251282e625c2; bacartx=6px; bacarty=28px; baminimized=true; 8812c36aa5ae336c2a77bf63211d899a=Yd8oM34V3OI8yF2uefgInZQ0rpe4SN1%2FfGnGhyIobGwuhds4fBU6RYIl2JkL%2BuG8%2FubSWeqLAyYAhwdbksr%2FmoS0uvljljWMjM7AiVroYZlbhlOlS7kU4I%2Ff3%2BmWjmaSEVwE97HyZsq%2BgxAgOI3JEhZQS6Hh2R6hOJsHXQJ672gfrnwd6M6YCQjr3Op9moGXg5tl19PpF4pyKZYffOkqozIhOjoSWwzyFAUARRQaq0GB5RuKpoxsSRIail3xj4DfzN3qfNl6wC5Mm9yBykl8pUDoxtnT1IZ37TeJcyGAMmCkjhkebY1ofMM5o9S3OL2oYbXUxMuaMOeMMi98tTfZscgm2O4d5tF12%2B7bBWkNmrly6lP57dQxPECj9KoI1zJvoKxAPM2DVJm0gqXurtls%2Bz6dBm8R1lpwTMONdAJlbFkO0EVBt1895o5BS7802VYShLflU5O%2BWUnsjikV87nct0Z%2BH9DAD2KCpQL%2FCNlXGhaOfR1R86zv3JDqlH8QovKQ000382; bauser=Tzo5OiJ1c2VyU3RhdGUiOjU6e3M6MjI6IgB1c2VyU3RhdGUAY3VzdG9tZXJfaWQiO3M6MzoiMTMyIjtzOjE5OiIAdXNlclN0YXRlAGd1ZXN0X2lkIjtzOjU6IjEyODExIjtzOjE4OiIAdXNlclN0YXRlAGNhcnRfaWQiO3M6NDoiMjA4NyI7czoxNToiAHVzZXJTdGF0ZQBoYXNoIjtzOjMyOiI3ODQxNjQzYmY1MDNkNDQyOWViNjBlMjZmYmEyMjZlNSI7czoyMToiAHVzZXJTdGF0ZQBzZXNzaW9uX2lkIjtzOjEyOiIwMzAxYWUxMGNkNWIiO30%3D; baemailcollected=-%7C2087; GZ=0; csm-hit=s-0JKFYAAE1F2KE1N9SHF8|1448276131400
Host:localhost:6646
Origin:http://evil.com/
Referer:http://localhost:6646/am.php/shop=http://www.amazon.com/b/ref=br_imp?_encoding=UTF8&node=384082011&pf_rd_m=ATVPDKIKX0DER&pf_rd_s=desktop-0&pf_rd_r=00RR74J82DEFP3GQQ4QD&pf_rd_t=36701&pf_rd_p=2292637582&pf_rd_i=desktop
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36
X-Requested-With:XMLHttpRequest
Query String Parameters
nocache:1448276132472
Form Data
{"requestMetadata":{"marketplaceID":"ATVPDKIKX0DER","clientID":"goldbox_mobile_pc","sessionID":"185-0313407-6286464"},"dealTargets":[{"dealID":"32183df1"},{"dealID":"76f45d7f"},{"dealID":"7c51ac4c"},{"dealID":"8bbb2fdb"},{"dealID":"ce448e92"},{"dealID":"d67a27b4"},{"dealID":"dcafa111"}],"responseSize":"ALL","itemResponseSize":"DEFAULT_WITH_PREEMPTIVE_LEAKING"}:
答案 0 :(得分:3)
$ _POST为空,因为帖子不是key:value格式。
在这种情况下你应该做
if ( strtolower($_SERVER['REQUEST_METHOD']) == 'post' ) {
$post = file_get_contents('php://input');
}