我希望通过Ajax在函数中发送cUrl请求。
这是我的cUrl请求:
function cUrlConnection ($url, $username, $password, $ch) {
$pass = md5($password);
$data = array(
'username' => $username,
'password'=> $pass,
);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; pl; rv:1.8.0.4) Gecko/20060426 Firefox/1.5.0.4');
curl_setopt($ch, CURLOPT_TIMEOUT, '40');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
$pos = strpos($result, "התחברת בהצלחה");
if ($pos === false) {
return false;
}
else
{
return $ch;
}
}
$chs = cUrlConnection($url, $username, $password, $ch);
我想通过Ajax将带有函数的变量$ chs发送到另一个文件。 我是怎么做到的?
答案 0 :(得分:0)
更改此内容(因为使用这样的数组会使其成为多部分表单发布):
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
成:
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));