Я пытаюсь получить информацию со старого сайта, который использует файлы cookie HTTP-файлов netscape для входа в систему. Вот мои локоны запросы:Curl with cookies to 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);
есть способ сделать это, используя HTTP пакета ИПП в Go?
Используйте [ 'http.CookieJar'] (http://golang.org/pkg/net/http/#Cookie Jar) для управления куки-файлами между несколькими запросами. Для ознакомления см. Родственный вопрос [В чем разница между cookie и cookiejar?] (Http://stackoverflow.com/questions/31270461/what-is-the-difference-between-cookie-and-cookiejar) – icza