相关疑难解决方法(0)

使用curl提交/检索表单结果

我需要帮助尝试使用curl将数据发布到页面并在提交表单后检索结果.

我创建了一个简单的表单:

<form name="test" method="post" action="form.php">              
    <input type="text" name="name" size="40" />
    <input type="text" name="comment" size="40" />
    <input type="submit" value="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)

另外,我有php代码在同一页面中处理这个表单.它所做的只是回显表单值.

我一直在使用的卷曲是这样的:

  $h = curl_init();

  curl_setopt($h, CURLOPT_URL, "path/to/form.php"); 
  curl_setopt($h, CURLOPT_POST, true);
  curl_setopt($h, CURLOPT_POSTFIELDS, array(
  'name' => 'yes',
  'comment' => 'no'
  ));
  curl_setopt($h, CURLOPT_HEADER, false);
  curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);

  $result = curl_exec($h);
  echo $result;
Run Code Online (Sandbox Code Playgroud)

当我启动包含curl代码的页面时,我得到了form.php页面内容,但它没有显示PHP在提交表单时应该回显的变量.

我很感激任何帮助.

谢谢.

php post curl libcurl

10
推荐指数
1
解决办法
2万
查看次数

标签 统计

curl ×1

libcurl ×1

php ×1

post ×1