Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用cURL将表单数据发布到简单表单_Php_Curl - Fatal编程技术网

Php 使用cURL将表单数据发布到简单表单

Php 使用cURL将表单数据发布到简单表单,php,curl,Php,Curl,我有一个简单的示例表单myForm.php <html> <head> <title>Curling and Enjoying?</title> </head> <body> <form action="print.php" method="post"> <p>First name: <input type="text" name="firstname" /></p>

我有一个简单的示例表单
myForm.php

<html>
<head>
<title>Curling and Enjoying?</title>
</head>
<body>
<form action="print.php" method="post">
   <p>First name: <input type="text" name="firstname" /></p>
   <p>Last name: <input type="text" name="lastname" /></p>
   <input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
<?php
   echo("First name: " . $_POST['firstname'] . "<br />\n");
   echo("Last name: " . $_POST['lastname'] . "<br />\n");
?>
如果可能,在向表单发布数据时,如何使用cURL通过向服务器提交参数来获得正确的HTML响应

当我运行命令时:

$curl-d“firstname=Ray&lastname;=Charles”http://mysiteurl.com/myForm.php

<html>
<head>
<title>Curling and Enjoying?</title>
</head>
<body>
<form action="print.php" method="post">
   <p>First name: <input type="text" name="firstname" /></p>
   <p>Last name: <input type="text" name="lastname" /></p>
   <input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
<?php
   echo("First name: " . $_POST['firstname'] . "<br />\n");
   echo("Last name: " . $_POST['lastname'] . "<br />\n");
?>

我只从myForm.php中获取HTML,提交目标应该是
print.php
,而不是
myForm.php

$ curl -d "firstname=Ray&lastname=Charles" http://mysiteurl.com/print.php

您可能想要curl print.php而不是myForm.php