[英]Using file_get_contents in php to send a GET request
can I use file_get_contents to send an http request to my host with GET parameters?我可以使用 file_get_contents 使用 GET 参数向我的主机发送 http 请求吗? If yes, I have other 3 questions: Firstly, how?
如果是,我还有其他 3 个问题:首先,如何? Can I use https instead of http?
我可以使用 https 代替 http 吗? Can I send them to another host (an external one)?
我可以将它们发送到另一台主机(外部主机)吗? Thx in advance, pls don't blame me if it is stupid
提前谢谢,如果它很愚蠢,请不要怪我
Yes.是的。
?
?
: ?param1=value1¶m2=value2
. ?param1=value1¶m2=value2
。 You can use http_build_query()
to convert an associative array to URL query parameters.http_build_query()
将关联数组转换为 URL 查询参数。https:
in the URL.https:
放入 URL 中即可。$result = file_get_contents('https://www.google.com/search?q=words+to+search+for');
file_get_contents is a stream fonction, so you can create a stream context and pass it to this function: file_get_contents 是一个 stream 函数,因此您可以创建一个 stream 上下文并将其传递给此 function:
$context = stream_context_create(
array( 'https' => // or any other protocol
array(
'method' => 'GET', // or post ..
// any other params you need
)
)
$response = file_get_contents('https://my-api.com/users' . http_build_query($params), false, $context);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.