検索


ほかのURLにアクセスするときPHP
更新:2017年08月25日 10時17分07秒
ほかのURLにアクセスするときPHP マストドンでGETタイプのアプローチ $control_URL = "/api/v1/timelines/public?limit=80"; $header = array( 'Authorization: Bearer '.$access_token, 'Content―Type: application/json', ); $context = stream_context_create(array( 'http' => array( 'method' => 'GET', 'header' => implode(PHP_EOL,$header), 'ignore_errors' => true, ) )); $html = mb_convert_encoding(file_get_contents(MASTODON_URL.$control_URL, FALSE, $context), 'UTF―8', 'auto'); $data = json_decode($html); cURL使うとき $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, MASTODON_URL. '/api/v1/accounts/'.$targetID); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer {$access_token}")); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); $data = json_decode($response); プロキシとか使ってアクセスするとき //――――――――――――――――// function GET_webdata($URL,$REF,$proxy){ //リファラアドレス $refURL=$REF; //Agent作成 $useragent = array(); $useragent[] = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7"; $useragent[] = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11"; $useragent[] = "Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1"; $useragent[] = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)"; $useragent[] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"; $useragent[] = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; ja―jp) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5"; $useragent[] = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A525 Safari/8536.25"; $uaRnd = rand(0,(count($useragent)―1)); $SELECTED_ua=$useragent[$uaRnd]; //header // $header = array( // "User―Agent: ".$SELECTED_ua, // "Referer: ".$refURL, // "Content―Type: application/x―www―form―urlencoded", // "Content―Length: ".strlen($post_data) // ); $header = array( "User―Agent: ".$SELECTED_ua, "Referer: ".$refURL, "Content―Type: text/html", "Content―Length: ".strlen($post_data) ); //option if(strlen($proxy)>0){ $context = array( "http" => array( "method" => "GET", "header" => implode("
", $header), "proxy" => "$proxy", 'request_fulluri' => true, ) ); }else{ $context = array( "http" => array( "method" => "GET", "header" => implode("
", $header) ) ); } //Webページデータ取得 return mb_convert_encoding(@file_get_contents($URL, FALSE, stream_context_create($context)), 'UTF―8', 'auto'); } //――――――――――――――――// } 単純アクセス $html = mb_convert_encoding(file_get_contents($URL), 'UTF―8', 'auto'); SSL経由 $ctx = stream_context_create(array('ssl'=>array('capture_session_meta'=>"TRUE"))); $html = mb_convert_encoding(file_get_contents($URL, FALSE, $ctx), 'UTF―8', 'auto');
日付: 事柄: パラメータ:
関連項目設定
ファイル読み込むphp.txt1KB2017年08月25日 10時17分07秒