晚上好,我想使用cURL通过twitter连接到https://accounts.nintendo.com/网站,因此我首先在nintendo网站连接页面上发出了GET请求,以获取csrf_token,然后向其中的动作URL发送POST请求。任天堂站点表单以便通过Twitter进行连接。
通常情况顺利时,回答请求应将我发送回去:302找到,然后找到通过oAuth通过Twitter与我联系的链接。
我试图修改userAgent和Header
<?php
include('simple_html_dom.php');
// SHOW THE PAGE TO GET CSRF TOKEN
$ch = curl_init();
$url = 'https://accounts.nintendo.com/login';
curl_setopt_array($ch,
array(
CURLOPT_URL => $url,
CURLOPT_CAINFO => dirname(__FILE__)."/cacert.pem",
CURLOPT_COOKIESESSION => false,
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36",
CURLOPT_HTTPHEADER => array(
'Host: accounts.nintendo.com',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'Pragma: ',
'Connection: keep-alive',
),
CURLINFO_HEADER_OUT => true,
CURLOPT_COOKIEFILE => dirname(__FILE__) . "/cookies.txt",
CURLOPT_COOKIEJAR => dirname(__FILE__) . "/cookies.txt",
CURLOPT_FRESH_CONNECT => false,
// The data to transfer with the response.
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
)
);
$data = curl_exec($ch);
// PARSER THE TOKEN CSRF
$dom = new simple_html_dom();
$html = $dom->load($data);
foreach($html->find('li[class="LoginForm_snsButton LoginForm_snsButton-row LoginForm_snsButton-twitter"] input[name="csrf_token"]') as $element)
{
$csrf_token = $element->value.'<br/>';
}
curl_close($ch);
//SEND POST REQUEST
$ch2 = curl_init();
$url = 'https://accounts.nintendo.com/federation/twitter';
$postData = array(
"post_federation_redirect_uri" => "https://accounts.nintendo.com/",
"post_federation_reauthenticate" => "",
"redirect_after" => "5",
"csrf_token" => $csrf_token,
"display" => ""
);
curl_setopt_array($ch2,
array(
CURLOPT_URL => $url,
CURLOPT_CAINFO => dirname(__FILE__)."/cacert.pem",
CURLOPT_COOKIESESSION => false,
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
CURLOPT_COOKIEFILE => dirname(__FILE__) . "/cookies.txt",
CURLOPT_COOKIEJAR => dirname(__FILE__) . "/cookies.txt",
CURLOPT_FRESH_CONNECT => false,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => http_build_query($postData),
CURLINFO_HEADER_OUT => true,
// The data to transfer with the response.
CURLOPT_HEADER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
)
);
$exec = curl_exec($ch2);
$header = curl_getinfo($ch2);
echo $header['request_header'].'</br></br></br>';
echo $header['header_size'];
echo $exec;
curl_close($ch2);
?>
问题是我收到了一个很好的403 Forbidden(我不知道是否是因为我正在从本地主机发出请求),这是一个显示请求标头,响应标头和站点响应内容的屏幕:http://www.noelshack.com/2019-15-6-1555110358-screenshot-1.jpg
答案 0 :(得分:-2)
您对 simple_html_dom.php 和您的脚本的 chmod权限是什么?
如果您没有授予权限 644 ,请尝试以下操作:
用$chmod 644 YourScript.php
然后,在第二种情况下,将脚本重新加载到Web浏览器上,并等待错误403 ,然后查看日志文件。
/var/log/apache2/error.log
/var/log/nginx/error.log
将您的结果告诉我,以便为您提供更好的帮助。 ;)