php不接受HTTP post请求


http post request not accepted by php

我是php和stackovrflow的新手。所以请原谅我最初的错误。我通过extjs4应用程序发送post请求。根据Mozilla控制台网络选项卡,请求被发送。PHP是5.4.25。详情如下:

POST /Opp/annt.php HTTP/1.1
Host: localhost
Connection: keep-alive
Content-Length: 83
Origin: http://localhost
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: */*
Referer: http://localhost/opp/index.html?_dc=140
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Form Dataview parsed
aaa=i&bbb=i&ccc=&ddd=&eee=4&fff=5&ggg=&hhh=
PHP文件:

header('Content-Type: application/json');
$method = $_SERVER["REQUEST_METHOD"];
$con = new PDO("mysql:host=localhost;dbname=openclass", "root", "")  or die("cannot connect to mysql");
    $fileContents = file_get_contents("php://input");
  echo $fileContents;
  json_decode($fileContents, true);
function getPostValue($postData, $fieldName) {
    return (!empty($postData[$fieldName]) ? htmlspecialchars($postData[$fieldName]) : NULL);
}

我没有得到任何数据后,post请求被执行。你能帮我指出可能的问题和解决方案吗?

我解决了问题。我得到错误,因为http post在application/x-www-form-urlencoded中发送表单数据;charset = formt utf - 8。我使用AJAX请求将发送的格式更改为json。这改变了发送到json键值对的格式。