【问题标题】:php send post request with a case?php发送带有案例的post请求?
【发布时间】:2018-02-22 10:44:43
【问题描述】:

我有以下方法从我的后台 php 脚本发送一个 post 请求到另一个 php 脚本:

$url = "ajax.php"; 
$res = @file_get_contents($url, false, stream_context_create([
    "http" => [
               "method" => "POST",
               "content" => http_build_query($params, $_REQUEST['action'] = 'save_attach_command'),
              ],
]));

'ajax.php'是一个长脚本,在switch case中分割,我想输入'save_attach_command' case,我做错了什么?

任何帮助将不胜感激!

谢谢

【问题讨论】:

    标签: php post switch-statement


    【解决方案1】:

    您使用 http_build_query 错误。它的第二个参数是;

    数字前缀 如果在基本数组中使用数字索引并提供了此参数,则它将仅添加到基本数组中元素的数字索引之前。

    因此代码应该是:

    $url = "ajax.php";
    $params['action'] = 'save_attach_command';
    $res = @file_get_contents($url, false, stream_context_create([
        "http" => [
            "method" => "POST",
            "content" => http_build_query($params),
        ],
    ]));
    

    【讨论】:

      猜你喜欢
      • 2017-07-13
      • 1970-01-01
      • 2021-03-12
      • 2018-08-13
      • 2011-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-30
      相关资源
      最近更新 更多