我已经完成了this post中的所有回复 的print_r($ _ POST); ===>返回空数组 的print_r($ _ SERVER);
Array ( [HTTP_HOST] => localhost
[HTTP_ACCEPT] => */*
**[HTTP__CONTENT_TYPE]** => application/json; charset=UTF-8"
[CONTENT_LENGTH] => 942
**[CONTENT_TYPE]** => application/x-www-form-urlencoded
[PATH] => /usr/local/bin:/usr/bin:/bin
[SERVER_SIGNATURE] => Apache/2.2.14 (Ubuntu) Server at localhost Port 80
[SERVER_SOFTWARE] => Apache/2.2.14 (Ubuntu)
[SERVER_NAME] => localhost
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 127.0.0.1
[DOCUMENT_ROOT] => /var/www
[SERVER_ADMIN] => webmaster@localhost
[SCRIPT_FILENAME] => /var/www/slocation.php
[REMOTE_PORT] => 50657
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => POST
[QUERY_STRING] =>
[REQUEST_URI] => /slocation.php
[SCRIPT_NAME] => /slocation.php
[PHP_SELF] => /slocation.php
[REQUEST_TIME] => 1288466907
)
HTTP__CONTENT_TYPE和CONTENT_TYPE有什么区别?
的print_r($ HTTP_RAW_POST_DATA); ==>返回发布的正确数据
的file_get_contents( 'PHP://输入'); ======>返回正确的数据。
只有$ _POST失败。
这是我的卷曲命令
$url = "http://localhost/slocation.php";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array('"Content-type: application/json; charset=UTF-8"'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$result = curl_exec($ch);
UPDATE :::::::::::::::::::::::::::::::::::::::::::::: ::::
我找到了一位大师here
答案 0 :(得分:1)
要回答我自己的问题,“HTTP__CONTENT_TYPE和CONTENT_TYPE有什么区别?”
如果您看到“HTTP__CONTENT_TYPE”,则很可能意味着您在设置CONTENT-TYPE标头字段时出错。也许,当curl无法识别有效的CONTENT_TYPE值时,错误的值设置为HTTP__CONTENT_TYPE,CONTENT_TYPE采用默认值。