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); giv开发者_StackOverflow中文版es me a blank page with the text:
Curl failed: Could not resolve host: login; Host not found
try to put an absolute url instead of a relative one
Use RETURNTRANSFER if you want the results returned from the curl_exec() call
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
and use the handle $ch when calling curl_error()
$ret_val = curl_error($ch);
精彩评论