質問があります。最初にデータをサイトに投稿してから、データを投稿したサイトのソースコードを取得することはできますか?
私はこれで試しました:
$html = file_get_contents('http://test.com/test.php?test=test');
しかし、?test=testは$_GET...です。
そうそう、誰かが私を助けてくれることを願っています!:)
よろしくお願いします(英語が下手でごめんなさい!)。
質問があります。最初にデータをサイトに投稿してから、データを投稿したサイトのソースコードを取得することはできますか?
私はこれで試しました:
$html = file_get_contents('http://test.com/test.php?test=test');
しかし、?test=testは$_GET...です。
そうそう、誰かが私を助けてくれることを願っています!:)
よろしくお願いします(英語が下手でごめんなさい!)。
この関数の 3 番目のパラメーターを使用できます: context
$postdata = http_build_query(
array(
'var1' => 'some content',
'var2' => 'doh'
)
);
$opts = array(
'http' => array(
'method' => "POST",
'header' => "Connection: close\r\n".
"Content-Length: ".strlen($postdata)."\r\n",
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://example.com/submit.php', false, $context);
// 編集 - 小さなバグは次のようになります:
$opts = array(
'http' => array(
'method' => "POST",
'header' => "Connection: close\r\n".
"Content-type: application/x-www-form-urlencoded\r\n".
"Content-Length: ".strlen($postdata)."\r\n",
'content' => $postdata
)
);
ソースを取得することはできませんが、サーバーによって提供されるページ/出力を取得できます。あなたが言及file_get_contents()
したように、それを使用して POST 要求を送信できますが、次のようになります。
// Create map with request parameters
$params = array ('surname' => 'Filip', 'lastname' => 'Czaja');
// Build Http query using params
$query = http_build_query ($params);
// Create Http context details
$contextData = array (
'method' => 'POST',
'header' => "Connection: close\r\n".
"Content-Length: ".strlen($query)."\r\n",
'content'=> $query );
// Create context resource for our request
$context = stream_context_create (array ( 'http' => $contextData ));
// Read page rendered as result of your POST request
$result = file_get_contents (
'http://www.sample-post-page.com', // page url
false,
$context);
// Server response is now stored in $result variable so you can process it
例: http://fczaja.blogspot.se/2011/07/php-how-to-send-post-request-with.html