0
我試圖從利用netscape HTTP cookie文件登錄的舊網站獲取信息。這裏是我的捲曲請求:用曲奇向Golang發出HTTP請求
// Do login request and get cookie
curl -c cookies -X POST -i -v https://foobar.com/login
// Use generated cookie file to get more data about the user
curl -b cookies -i -v https://foobar.com/data
在PHP中,你可以這樣做:
// Do login request and get cookie
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://foobar/login');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, './cookies');
curl_setopt($ch, CURLOPT_COOKIEFILE, './cookies');
$user = curl_exec($ch);
// Use generated cookie file to get data about the user
curl_setopt($ch, CURLOPT_URL, 'https://foobar/login');
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, './cookies');
curl_setopt($ch, CURLOPT_COOKIEFILE, './cookies');
$data = curl_exec($ch);
有沒有辦法做到這一點使用在Go性病HTTP包?
使用的['http.CookieJar'](http://golang.org/pkg/net/http/#Cookie Jar)在多個請求之間管理Cookie。有關介紹,請參閱相關問題[cookie和cookiejar有何區別?](http://stackoverflow.com/questions/31270461/what-is-the-difference-between-cookie-and-cookiejar) – icza