You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用CURL对未知参数的PHP链接自动填充POST请求值?

批量处理未知POST参数的curl请求方案

要实现自动识别目标PHP页面的POST参数并统一设置为指定值(比如hello world),核心思路是先抓取页面提取所有表单参数,再拼接参数发送POST请求。以下是两种可行方案:

方案1:原生命令行工具(无需额外安装)

用curl配合grep、awk这类原生工具提取参数,适合不想装第三方工具的场景:

while read url; do
  # 抓取页面,提取所有带name属性的input标签的参数名并去重
  params=$(curl -s --connect-timeout 18 --cookie "" --user-agent "" "$url" | \
    grep -E '<input[^>]+name="[^"]+"' | \
    awk -F 'name="' '{print $2}' | awk -F '"' '{print $1}' | \
    sort -u)

  # 拼接成"param1=hello%20world&param2=hello%20world"格式
  if [ -n "$params" ]; then
    post_data=$(echo "$params" | awk '{print $0 "=hello%20world"}' | paste -sd '&' -)
  else
    post_data=""
  fi

  # 发送POST请求并记录URL和耗时
  curl -X POST --connect-timeout 18 --cookie "" --user-agent "" -d "$post_data" \
    -w "%{url}:%{time_total}s\n" "$url"
done < domain.txt > output.txt

方案2:用htmlq工具(更可靠的HTML解析)

正则匹配HTML容易出问题,推荐用专门的HTML解析工具htmlq(Debian/Ubuntu可通过apt install htmlq安装,macOS用brew install htmlq),能更精准提取参数:

while read url; do
  # 提取表单中除按钮外的所有输入参数名(排除submit/reset/button类型)
  params=$(curl -s --connect-timeout 18 --cookie "" --user-agent "" "$url" | \
    htmlq --attribute name 'input[name]:not([type="submit"]):not([type="reset"]):not([type="button"])')

  # 拼接参数
  if [ -n "$params" ]; then
    post_data=$(echo "$params" | awk '{print $0 "=hello%20world"}' | paste -sd '&' -)
  else
    post_data=""
  fi

  # 发送请求
  curl -X POST --connect-timeout 18 --cookie "" --user-agent "" -d "$post_data" \
    -w "%{url}:%{time_total}s\n" "$url"
done < domain.txt > output.txt

关键注意点

  • 如果目标页面的表单是JS动态生成的,静态抓取页面的方式拿不到参数,得用puppeteer或phantomjs这类无头浏览器工具渲染页面后再提取。
  • hello%20world是hello world的URL编码,也可以直接用"hello world",curl会自动处理编码,但手动编码能避免特殊字符的问题。
  • 脚本会提取页面中所有符合条件的参数,如果只需要特定表单的参数,可以调整htmlq的选择器(比如加上表单ID:#target-form input[name])。

内容的提问来源于stack exchange,提问作者Danis Vakik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 06:35:26