1
我需要寫一個機器人登陸到網站,並做一些查詢,問題是這樣的網站是寫在ASP.NET MVC,需要兩個cookie來識別用戶!我可以用我的PHP捲曲但對方一個.AspNet.ApplicationCookie(這是一樣大〜400KB)不能存儲保存一個餅乾!PHP捲曲不能保存ASP.net MVC生成的cookie
這裏是我的代碼:
$ch = curl_init('MY URL...');
$cookie = __DIR__ . '/cookie.txt';
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "UserName=123&Password=123");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
$result = curl_exec($ch);
var_dump($result);
與cookie.txt文件會發生什麼,它保持爲空?我想你需要添加'CURLOPT_COOKIESESSION'參數。例子:curl_setopt($ ch,CURLOPT_COOKIESESSION,true);如果這不起作用,請檢查您的cookie.txt文件權限。可能是因爲權限錯誤,PHP無法寫入文件。 – Sander
沒有我的cookie.txt不是空它有一個餅乾的所有信息!我嘗試了CURLOPT_COOKIESESSION選項,但仍然沒有快樂! –