file_get_contentsã§POSTãã¼ã¿éä¿¡
æ¬æ¥ããPHPã®ã¡ã¢ãè¨è¿°ãã¦è¡ããã¨æãã¾ãã
ãã¦æ©éä»æ¥ã®ãã¿ã
ããã ã£ãããã«ã¦file_get_contentsã§Webãã¼ã¸ã¸ã¢ã¯ã»ã¹ããéã«ãUserAgentãå¤æ´ããæ¹æ³ãç´¹ä»ããã¦ãã¾ãã
ã§ã¯ããããå¿ç¨ãã¦file_get_contentsã使ã£ã¦POSTå½¢å¼ã§ãã¼ã¿ãéä¿¡ãã¦ã¿ã¾ãããã
åèã³ã¼ã
<?php //POSTãã¼ã¿ $data = array( "param1" => "data1", "param2" => "data2" ); $data = http_build_query($data, "", "&"); //header $header = array( "Content-Type: application/x-www-form-urlencoded", "Content-Length: ".strlen($data) ); $context = array( "http" => array( "method" => "POST", "header" => implode("\r\n", $header), "content" => $data ) ); $url = "http://localhost/test.php"; echo file_get_contents($url, false, stream_context_create($context)); ?>
ãããªæãã§ãã
åãåãå´ã®ããã°ã©ã ã¯print_r($_POST);ã¨ããã¦ãããã°çµæãè¦ãããã¨æãã¾ãã
éè¦ãªã®ã¯stream_context_createã§ããã
headerã«ã¯é©åãªããããè¨å®ããcontentã«POSTãã¼ã¿ãå ¥ãã¦ãããã°ããã§ãã
ãã®æ¹æ³ãªããcurlãPEARï¼HTTP_Clientã¨ãï¼çã使ç¨ããã«POSTãã¼ã¿ãéä¿¡ã§ããããã«ãªãã¾ãã