ホームページ >バックエンド開発 >PHPチュートリアル >file_get_contens 関数がパラメータをローカル ファイルに渡す際の PHP の問題
ローカルファイルにパラメータを渡す file_get_contens 関数に関する PHP の問題
ソースコードは次のとおりです:
$str_query = "userId=admin&gameId=game1&serverId=server1"
$context= stream_context_create(array(
) 'http' => array(
'method'=> 'POST',
'timeout' => 10,
'header'=> 'ユーザーエージェント: Mozilla/5.0 (Windows; U; Windows NT) 5.1; en -US) AppleWebKit/534.13 (Gecko のような KHTML) Chrome/9.0.597.98 Safari/534.13rnContent-type: application/x-www-form-urlencodedrn',
'content'=> )
));
echo file_get_contents("interface.php",true, $context);
?>
ローカル Apache サーバーには 2 つのファイルしかありません。 1 つは上記のソース コードを含むファイルです。 1 つは、interface.php ファイルです。
このファイルに上記のソースコードを書きます。 file_get_contents を使用して、interface.php ファイルにデータを POST します。その結果、interface.php はデータを受信できませんでした。
どこで間違ったのか分かりません。専門家にアドバイスを求めましょう! ! ! !
echo file_get_contents(" http://localhost/interface.php",true, $context);
さらに、
'header'=> "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.13 (KHTML、Gecko など) Chrome/9.0 として記述する必要があります。 597.98 Safari/534.13rnContent-type: application /x-www-form-urlencodedrn",
二重引用符で囲まれた rn のみが有効になります
ヘッダー項目は
'header として記述する必要があります'=> "ユーザー エージェント: Mozilla/5.0 (Windows ; U; Windows NT 5.1; en-US) AppleWebKit/534.13 (KHTML、Gecko など) Chrome/9.0.597.98 Safari/534.13rnContent-type: application/x- www-……
3 階からの引用:
さらに、
ヘッダー項目パラメータ配列には
'header'=> "User-Agent: Mozilla /5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.13 (Gecko のような KHTML) Chrome/9.0.597.98 のように記述する必要があります。 Safari/534.13rnContent-type: app...
インターネット プロトコルはなく、ファイル システム機能のみです。猿に飛べとばかり言っても無理です。 Sun Wukong は、Patriarch Bodhi の指示に従って宙返りをしました