简单的 cURL 不起作用
我想使用 cURL 自动发布表单。 这是我想用 cURL 发布的表单:
<form action="login/main_login.php" method="post">
<input type="hidden" name="url" value="index.php" />
<input type="submit" value="Submit" />
</form>
我使用这个代码:
$ch =curl_init();
curl_setopt($ch, CURLOPT_URL, 'login/main_login.php');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "url=index.php");
$data = curl_exec($ch);
curl_close($ch);
但它不起作用,它甚至没有将我发送到 login/main_login.php。 我正在使用 wampserver 并通过取消注释 extension=php_curl.dll 编辑了两个 php.ini 文件。
使用 echocurl_error(); 给我以下错误:
curl_error() expects exactly 1 parameter, 0 given inWarning: curl_error() expects exactly 1 parameter, 0 given in C:\wamp\www\website\page.php on line 10
放在
if($data==FALSE)
{
die("Curl failed: " . curL_error($ch));
}
curl_close($ch);前面给我一个空白页,其中包含以下文字:
Curl 失败:无法解析主机:登录;找不到主机
I want to use cURL to automatically post a form.
This is the form I want to post with cURL:
<form action="login/main_login.php" method="post">
<input type="hidden" name="url" value="index.php" />
<input type="submit" value="Submit" />
</form>
I use this code:
$ch =curl_init();
curl_setopt($ch, CURLOPT_URL, 'login/main_login.php');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "url=index.php");
$data = curl_exec($ch);
curl_close($ch);
But it isn't working, it is not even sending me to the login/main_login.php.
I am using wampserver and edited both php.ini files by uncomment extension=php_curl.dll .
Using echo curl_error();
gives me the following error:
curl_error() expects exactly 1 parameter, 0 given inWarning: curl_error() expects exactly 1 parameter, 0 given in C:\wamp\www\website\page.php on line 10
Putting
if($data==FALSE)
{
die("Curl failed: " . curL_error($ch));
}
in front of curl_close($ch); gives me a blank page with the text:
Curl failed: Could not resolve host: login; Host not found
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试输入绝对网址而不是相对网址
try to put an absolute url instead of a relative one
如果您希望从curl_exec()调用返回结果,请使用RETURNTRANSFER
,并在调用curl_error()时使用句柄$ch
Use RETURNTRANSFER if you want the results returned from the curl_exec() call
and use the handle $ch when calling curl_error()