【问题标题】:php - Handle application/x-www-form-urlencoded POST request using phpphp - 使用 php 处理 application/x-www-form-urlencoded POST 请求
【发布时间】:2015-06-18 15:20:50
【问题描述】:

我正在尝试使用 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 有什么想法吗?

【问题讨论】:

  • 向我们展示您迄今为止所做的尝试,我们将帮助您解决遇到的任何问题。
  • 不,我不知道。 "data" 来自哪里?我们应该如何处理device_id=2112121&app_version=420

标签: php json content-type urlencode urldecode


【解决方案1】:

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

【讨论】:

  • 这既不会产生响应(正如 OP 所建议的那样),也不会在他的示例中发明额外的数据。
猜你喜欢
  • 2014-03-30
  • 1970-01-01
  • 1970-01-01
  • 2018-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-26
  • 2018-04-04
相关资源
最近更新 更多