HardCoreMore Posted December 12, 2010 Share Posted December 12, 2010 Hi guys, I know that you can open web page with $handle = fopen("http://www.example.com/", "r"); but i am wondering is there a way to pass POST vars when doing so, or there is another method that can that like you do it with ajax. I have mvc application that i want to test. I am using CodeIgniter framework so i want to call my controllers with POST values. Every controller method returns data holder object that holds the data of operation whether is successful or not. Also every method inside controller can be called with parameter input or with post input. If you omit the parameters when calling controller method than he will try to load that parameters from post and that is why i want to pass POST vars with php when calling controller for example i want to call: fopen("http://localhost/MyAppFolder/index.php/controller/method"); but i want to pass it some POST vars if that is possible Thanks. Quote Link to comment Share on other sites More sharing options...
HardCoreMore Posted December 12, 2010 Author Share Posted December 12, 2010 I just found solution on the web. Here it is if anybody needs it: $url = $settings['root_url'] . 'authentication/authenticate'; (string)$data = ''; $data .= 'username=username&'; $data .= 'password=password&'; $data .= 'key=44d7db2d-2656-102e-acf7-3c78a6d744cd'; $params = array('http' => array( 'method' => 'POST', 'content' => $data ) ); $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); $response = @stream_get_contents($fp); echo $response; Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.