2013-06-19 36 views
0

我正在用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數據的第二部分來執行表單。表單處理髮生在同一個網頁...

我的Connexion公司仍然有效,但我不知道,服務器是拍攝我的錯誤,如:

處理您的請求時發生異常。我們記錄了例外情況..

它並沒有幫助我。任何人有一個想法?

謝謝。

+0

你可以看看apache的日誌,也許它會提供更多的信息 – Jaay

+0

你可能需要詢問你正在調用的服務的開發者是否發生了什麼異常。很可能POST參數是無效的或某事。 – MarioP

+0

詢問誰提供錯誤消息是什麼例外。 – jterry

回答

0

此時您可能有SSL問題。 嘗試添加這些選項:

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

感謝您的建議,我嘗試了它,但仍然出現相同的錯誤消息。 – Peter

+0

你可以嘗試使用我創建的用於自動化的捲曲課程。我已經提出了一個使用示例,您嘗試在按鈕上。不要忘記在頂部定義常量。 http://pastebin.com/P00xQbxZ –

0

我終於收到了支援小組的解答。 「東部+標準+時間」應該是「東部標準時間」,服務器將自動逃脫這些字符串......請到所有人的幫助!