php - 如何在数组中设置 _GET
问题描述
$data2 = [
'a' => '(!isset($_GET["a"])) ? "default" : htmlspecialchars($_GET["a"]);',
'b' => '-(!isset($_GET["b"])) ? "default" : htmlspecialchars($_GET["b"]);',
'c' => '(!isset($_GET["c"])) ? "default" : htmlspecialchars($_GET["c"]);',
'd' => '(!isset($_GET["d"])) ? "default" : htmlspecialchars($_GET["d"]);',
];
curl_setopt($ch, CURLOPT_URL, "post request url");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data2));
curl_setopt($ch, CURLOPT_POST, 1);
$x = curl_exec($ch);
echo $x;
我在一个 php 中使用它,它通过以下请求调用一个 POST url 我将如何设置它,以便我可以编辑 1 个 php,例如放置 file.php?a=28.29.29&b=1232.231.121&c=2121&d= 8282832,它将为我填写帖子请求点,任何建议都会很棒
这是它通常手动的样子
$data2 = [
'a' => '228.29.29',
'b' => '-1232.231.121',
'c' => '2121',
'd' => '8282832',
];
解决方案
根据您的问题,似乎存在语法错误,请将 $data 替换为以下代码,它应该可以正常工作。
$data2 = [
'a' => (!isset($_GET["a"])) ? "default" : htmlspecialchars($_GET["a"]),
'b' => (!isset($_GET["b"])) ? "default" : "-" .htmlspecialchars($_GET["b"]),
'c' => (!isset($_GET["c"])) ? "default" : htmlspecialchars($_GET["c"]),
'd' => (!isset($_GET["d"])) ? "default" : htmlspecialchars($_GET["d"]),
];
curl_setopt($ch, CURLOPT_URL, "post request url");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data2));
curl_setopt($ch, CURLOPT_POST, 1);
$x = curl_exec($ch);
echo $x;
推荐阅读
- html - 如何使容器标题固定而不随内容滚动?
- qt - 在 QT 我有函数 xyz() 并且我需要同时返回 QImage 和 QString ?
- jpa - Spring Jpa 存储库 - Orm.xml
- c# - 将号码中继器添加到现有中继器
- robotframework - 为什么在 ${expression} 导致错误之前删除字母“C”?
- typescript - 打字稿:在算术运算中使用布尔类型
- angular - 角材料 - 垫表 - 排序和过滤不起作用?
- server - ejabberd 如何激活管理链接?
- django - Django - 使用 PostgreSQL 和 Elasticsearch 进行全文搜索
- android - 改造动态 URL 仍附加到基本 URL