Post 将带有curl的随机值发送到服务器

Post 将带有curl的随机值发送到服务器,post,curl,Post,Curl,假设我有一个HTML表单,如下所示: <form method="post" action="anmeldung.fcgi" onsubmit="return chkForm()"> <input type=text name="person"> <input type=hidden name="id" value="1234"> <!-- this value is generated --> <input type

假设我有一个HTML表单,如下所示:

<form method="post" action="anmeldung.fcgi" onsubmit="return chkForm()">
    <input type=text name="person">
    <input type=hidden name="id" value="1234"> <!-- this value is generated -->
    <input type=submit name="press" value="OK">
</form>

id中的值是由我们不知道的机制生成的,每次访问站点时,它都是另一个值。现在让我们假设收集数据的脚本检查id是否正确,然后才调用其余代码


curl有没有办法将具有正确id的数据发送到服务器?那么,我可以从页面中读出它并将其发送到服务器吗?我想我必须使用与HTML文件相同的“实例”或类似的东西?

听起来这将是一个多步骤的过程,但可以相当容易地编写脚本。首先,您可以使用curl访问表单的URL,如下所示:

curl http://hostname/path/to/form.html
curl --data "person=xxx&id=1234&press=OK"  http://hostname/path/to/anmeldung.fcgi
然后,您将解析从上述GET请求返回的内容,以提取填充在隐藏id字段中的值

然后,您可以使用curl向anmeldung.fcgi发送帖子,设置要发送的表单输入,如下所示:

curl http://hostname/path/to/form.html
curl --data "person=xxx&id=1234&press=OK"  http://hostname/path/to/anmeldung.fcgi

太好了,谢谢你。但是如何将值临时保存在变量中呢?我的建议是使用脚本语言(如PHP、perl、python、bash脚本等)编写脚本。这些语言中的任何一种都能够通过子shell运行curl命令,并将curl命令的结果读回变量。例如,在PHP中,您可以使用shell_exec来实现这一点。因此,PHP脚本将通过子shell执行第一个curl命令,将curl命令的结果存储在一个变量中,然后解析该变量的id值,然后执行第二个curl命令。