Форма входа и параметры публикации по curl - PullRequest
0 голосов
/ 12 мая 2019

Мне нужно войти в R-studio, чтобы получить (свернуться) изображение.Я использую процедуру, описанную ниже, но она не возвращает изображение, а только саму форму.Это расположение формы: http://skiweather.eu:8787/auth-sign-in

    <?php
$username = 'admin';
$password = 'XXX';
$loginUrl = 'http://skiweather.eu:8787/auth-do-sign-in';
$sign=1;
$cookie= "cookies.txt";

//init curl
$ch = curl_init();

//Handle cookies for the login
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true)

//Set the URL to work with
curl_setopt($ch, CURLOPT_URL, $loginUrl);

// ENABLE HTTP POST
curl_setopt($ch, CURLOPT_POST, 1);


$response = curl_exec($ch);
if (curl_errno($ch)) die(curl_error($ch));
$dom = new DomDocument();
$dom->loadHTML($response);
$tokens = $dom->getElementsByTagName("meta");
for ($i = 0; $i < $tokens->length; $i++)
{
    $meta = $tokens->item($i);
    if($meta->getAttribute('name') == 'csrf-token')
    $token = $meta->getAttribute('content');
}

$postinfo = 'username='.$username.'&password='.$password.'&staySignedIn=1&appUri='.$loginUrl.'&_csrf='.$token;
echo $token; //debug info
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);


//set the URL to the protected file
curl_setopt($ch, CURLOPT_URL, 'http://skiweather.eu:8787/files/R/devel/PLOTS/snowalert_today_0.png');

//execute the request
$content = curl_exec($ch);

curl_close($ch);

//save the data to disk
file_put_contents('pppp.png', $content);

?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...