php不接受http发布请求

时间:2014-07-19 09:05:41

标签: php post json

我是php和stackovrflow的新手。所以请原谅我最初的错误。 我通过extjs4 app发送邮件请求。根据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);
}

执行发布请求后,我没有收到任何数据。你可以在指出可能的问题和解决方案时给予帮助

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。我收到错误是因为http post正在application / x-www-form-urlencoded中发送表单数据; charset = UTF-8 formt。 我使用AJAX请求更改了发送到json的格式。这改变了发送到json键值对的格式。 这有助于它通过php阅读。