php - Sending post data along with file_get_contents() -


this question has answer here:

i read question stackoverflow:
how post data in php using file_get_contents? covers pretty in order explain how use file_get_contents() function in php

to practice, created these 2 php files :

1.php

<?php  $postdata = http_build_query(     array(         'name' => 'example',         'roll' => '123321'     ) );  $opts = array('http' =>     array(         'method'  => 'post',         'header'  => 'content-type: application/x-www-form-urlencoded',         'content' => $postdata     ) );  $context = stream_context_create($opts); $result = file_get_contents('http://localhost/2.php', false, $context); echo $result;  ?> 

and code for
2.php

<?php  $name = $_post['name']; $roll = $_post['roll'];  echo $name . "<br>" . $roll;  ?> 

the expected output 1.php should send "name" , "roll" 2.php using method="post" , contents of file , print them :

expected output :

example
123321

and output getting (as if no post data sent)

notice: undefined index: name in c:\xampp\htdocs\2.php on line 3

notice: undefined index: roll in c:\xampp\htdocs\2.php on line 4

http://www.php.net/manual/de/context.http.php#101933:

“watch case when using methods (post , get)...it must uppercase. in case of write in lower case wont work.”


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -