我正在使用 php 和 curl,我在使用enctype=multipart/form-data
.
远程网页中的表单:
<form method="post" enctype="multipart/form-data" action="/account/login" id="login">
<label for="username">Username</label><input name="username" id="username"><br>
<label for="password">Password</label><input name="password" id="password" type="password"><br>
<input type="checkbox" name="keeplogged" id="keeplogged" value="on"><label for="keeplogged">Remember me</label><br>
<input type="submit" name="submit" value="Submit" />
</form>
数据(来自post
Firefox):
POSTDATA =-----------------------------24464570528145
Content-Disposition: form-data; name="username"
fakeuser
-----------------------------24464570528145
Content-Disposition: form-data; name="password"
fakepass
-----------------------------24464570528145
Content-Disposition: form-data; name="keeplogged"
on
-----------------------------24464570528145
Content-Disposition: form-data; name="submit"
Submit
-----------------------------24464570528145--
我正在尝试使用 curl 登录:
function login($ref)
{
// Identify the URL:
$url = 'http://www.fakeSite.com/account/login';
$dt = array();
$dt['username'] = 'fakeUser';
$dt['password'] = 'fakePass';
$dt['keeplogged'] = 'on';
$dt['submit'] = 'Submit';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
curl_setopt($curl, CURLOPT_COOKIEJAR, "/tmp/cookie.txt");
curl_setopt($curl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $dt);
$result = curl_exec($curl);
if(curl_errno($curl))//If there is any error
{
echo 'Curl error: ' . curl_error($curl);
exit();
}
curl_close($curl);
return $result;
}
但结果什么都没有!没有结果,没有错误,什么都没有!有人知道吗?
PS:我试图传递格式类似于 Firefox 的 postfields,但这并没有解决问题。