php - 使用php处理application / x-www-form-urlencoded POST请求

时间:2015-04-13 10:34:57

标签: php json content-type urlencode urldecode

我正在尝试使用PHP处理application/x-www-form-urlencoded POST请求。客户以下列格式发送请求:

POST /index.php User-Agent: Android/4.0 
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip
action=Settings&device_id=2112121&app_version=420

服务器的响应必须如下:

{
    "action": "Settings",
    "data": {
        "entries": {
            "service_enabled": "true"
        }
    },
    "data_format": "json"
}

在服务器端对index.php有任何想法吗?

1 个答案:

答案 0 :(得分:-2)

试试这个$_POST = json_decode(file_get_contents("php://input"), true);