How to receive values which are sent by file
I sent values through file_get_contents.
My question is i am unable receive(print) GET method values in work.php.
I am using stream_context_create() this will create a resource id.
page name sendvalues.php
// Create a stream
$opts = array(
'http'=>array(
'method'=>"GET",
'phone' => "9848509317",
'msg' => "hi naveen"
)
);
echo $context = stream_context_create($opts);
$file = file_get_contents('http://www.aakrutisolutions.com/projects/testingsite/smstest/sms_http_curl/work.php', false, $context);
echo $file;
page name work.php
echo "";
print_r($_GET); /// i am unable to get my query string values
echo "
"; Just append your parameters url encoded to your url:
$file = file_get_contents('http://www.aakrutisolutions.com/projects/testingsite/smstest/sms_http_curl/work.php?phone=123&msg=hi%20naveen');
The context options you used... are context options. Here is specified which you can user for http: http://www.php.net/manual/de/context.http.php It's not to be transmitted if you put random stuff in there.
Your array is incorrect. Look at the examples at http://php.net/manual/en/function.file-get-contents.php. You cannot simply add POST arguments to the context array.
The correct context array for a POST request would look like this:
$opts = array(
'http' => array(
'method' => 'POST',
'content' => http_build_query(array(
'phone' => 9848509317,
'msg' => 'hi naveen'
))
)
);
Or simply use GET (as you expect in your other script), so put the arguments in the URL (build the query string with http_build_query() ).
上一篇: 如何在PHP POST请求后获取HTTP响应头文件?
下一篇: 如何接收文件发送的值
