2017-12-18 38 views
-5

このサイトでは、Curlで自動的にログインしようとしています:https://online.hinode.com.br、コンサルタントIDは、常に同じステータスと一緒に自動的に入力する必要があります。ログイン後、特定の製品ページにリダイレクトする必要があります。しかし、私がテストしたコードはどこにも行きませんでした!エラーはありません、htmlはロードされません...私はそれがこの選択フィールドであるべきだと思います。入力フィールドの1つであるCurlによる自動ログイン

コード:

<?php 
// Start cURL 
$ch = curl_init(); 
// Define the original URL (of the login form) 
curl_setopt($ch, CURLOPT_URL, 'https://online.hinode.com.br/'); 
// Enable POST protocol 
curl_setopt ($ch, CURLOPT_POST, 1); 
// Define the parameters that will be sent (user and password for example) 
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'loja_consultor=fulano&estado=SP'); 
// Imitate the boss behavior of browsers: handle cookies 
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 
// Set the transfer type (Padrão: 1) 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
// Execute the requisition 
$store = curl_exec ($ch); 
// Define a new URL to be called (after login) 
curl_setopt($ch, CURLOPT_URL, 'https://online.hinode.com.br/detalhes.asp?IdProduto=769&ssp=830852727SSP20171218HP115020'); 
// Execute the second request 
$content = curl_exec ($ch); 

//閉じるcURLの curl_close($ chを);

ありがとうございます!

enter image description here

enter image description here

enter image description here

enter image description here

+0

Downvotingを。 – pepperjack

+0

メインのスタックオーバーフローサイトに関する質問は英語で行う必要があります。[pt.so]を試してください。 – jmoerdyk

+0

Stack: –

答えて

0

これは動作します:英語でされていないが原因

<?php 
$cookie="cookie.txt"; 
$login_url = "https://online.hinode.com.br/loja_valida.asp"; 
$target_url="https://online.hinode.com.br/detalhes.asp?IdProduto=1294&ssp=1044632862SSP20171218HP180256"; 
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"; 

$field['loja_consultor'] = '228621'; 
$field['estado'] = 'SP'; 
$field['acessar'] = 'Acessar'; 

$datafield = http_build_query($field); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); 
curl_setopt($ch, CURLOPT_URL, $login_url); 
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datafield); 
curl_setopt ($ch, CURLOPT_POST, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 

curl_exec($ch); 

curl_setopt($ch, CURLOPT_URL, $target_url); 
$ket_qua = curl_exec($ch); 

echo $ket_qua; 

curl_close($ch); 
?> 
+0

Tksしかし、私がこれを試してみると、これはここから起こります:https://i.stack.imgur.com/TmDBs.png –

+0

あなたがサイトに行き、通常どおりにログインすれば、それは期待どおりに動作しますか? – tbedner

+0

あなたのイメージはあなたがインデックスページに302 redirctを取得することを示しています。 – tbedner

関連する問題