用$ _POST制作2个cURL请求

时间:2013-06-19 12:49:19

标签: php forms post curl

我正在尝试在cURL中进行2次重试。第一个请求是登录我,我保留了一个txt文件,以便在仍然显示时发出第二个请求。

第一部分像魅力一样,第二部分不起作用。

有我的代码。

$lien = 'https://mysite.com/login';
$postfields = array(
    'username' => 'test',
    'password' => 'test'
);


$path_cookie = 'connexion.txt';
if (!file_exists(realpath($path_cookie))) touch($path_cookie);

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $lien);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_COOKIEJAR, realpath($path_cookie));

$return = curl_exec($curl);

echo($return);
curl_close($curl);


$lien2 = 'https://mysite.com/myform';
$postfields2 = array(
    'data1'     => 'test123',
    'data2'     => 'Account',
    'sort'      => '3',
    'fileFormat'    => '0',
    'timezone'  => 'Eastern+Standard+Time',
    'zeroRated' => 'true',
    'startDate'     => '2013-05-01',
    'endDate'   => '2013-05-31'
);

$curl = curl_init();


curl_setopt($curl, CURLOPT_URL, $lien2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields2);
curl_setopt($curl, CURLOPT_COOKIEFILE, realpath($path_cookie));

$return = curl_exec($curl); 

echo $return;
curl_close($curl);

unlink(realpath($path_cookie));

我正在使用$ _post数据的第二部分来执行表单。表单处理在同一页面中进行...

我的联系仍然存在,但我不知道,服务器正在向我发出如下错误:

  

处理您的请求时发生异常。我们记录了例外..

这对我没有帮助。有谁有想法?

感谢。

2 个答案:

答案 0 :(得分:0)

此时您可能遇到SSL问题。 尝试添加以下选项:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);

答案 1 :(得分:0)

最后我收到了支持团队的回复。 “东部+标准+时间”应该是“东部标准时间”,服务器将自动逃脱这些字符串...向每个人提供帮助!

相关问题