I have gone through all the responses in this post
print_r($_POST); ===> returns empty array 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_TI开发者_如何学运维ME] => 1288466907
)
What's the difference between HTTP__CONTENT_TYPE and CONTENT_TYPE?
print_r($HTTP_RAW_POST_DATA); ==> returns correct data posted
file_get_contents('php://input'); ======> returns correct data.Only $_POST fails.
This is my curl command
$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::::::::::::::::::::::::::::::::::::::::::::::::::
I found a master hereTo answer my own question, "What's the difference between HTTP__CONTENT_TYPE and CONTENT_TYPE?"
If you see "HTTP__CONTENT_TYPE", it most probably means you have made mistake in setting the CONTENT-TYPE header field. Probably, when curl doesn't recognize the valid CONTENT_TYPE value, then the wrong value is set to HTTP__CONTENT_TYPE and CONTENT_TYPE takes a default value.
精彩评论