如何接收文件发送的值
我通过file_get_contents发送了值。
我的问题是我无法接收(打印)在work.php GET方法值。
我正在使用stream_context_create()这将创建一个资源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 "
“; 只需将你的参数url编码到你的url:
$file = file_get_contents('http://www.aakrutisolutions.com/projects/testingsite/smstest/sms_http_curl/work.php?phone=123&msg=hi%20naveen');
您使用的上下文选项...是上下文选项。 这里指定哪些用户可以使用http:http://www.php.net/manual/de/context.http.php如果你在那里放置随机的东西,它不会被传输。
你的数组不正确。 查看http://php.net/manual/en/function.file-get-contents.php上的示例。 你不能简单地将POST参数添加到上下文数组中。
POST请求的正确上下文数组看起来像这样:
$opts = array(
'http' => array(
'method' => 'POST',
'content' => http_build_query(array(
'phone' => 9848509317,
'msg' => 'hi naveen'
))
)
);
或者简单地使用GET(如您在其他脚本中所期望的那样),因此请将参数放入URL中(使用http_build_query()构建查询字符串)。
