简体   繁体   English

PHP的情况下发送后请求?

[英]php send post request with a case?

I have the following method to send a post request from my back-office php script to another php script : 我有以下方法将后勤php脚本中的发布请求发送到另一个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'),
              ],
]));

The 'ajax.php' is a long script divised in switch case, I want to enter in 'save_attach_command' case, what am I doing wrong ? “ ajax.php”是一个很长的脚本,用切换的情况划分,我想输入“ save_attach_command”的情况,我在做什么错呢?

Any help will be appreciated ! 任何帮助将不胜感激 !

Thanks 谢谢

You are using http_build_query wrong. 您使用的是http_build_query错误。 The second parameter to it is; 它的第二个参数是;

numeric_prefix If numeric indices are used in the base array and this parameter is provided, it will be prepended to the numeric index for elements in the base array only. numeric_prefix如果在基本数组中使用了数字索引,并且提供了此参数,则它将仅在基本数组中的元素的数字索引之前。

Therefore the code should be : 因此,代码应为:

$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),
    ],
]));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM