如何从 PHP 发送 GET 请求?
问题描述:
我打算使用 PHP 来满足一个简单的要求.我需要从 URL 下载 XML 内容,为此我需要向该 URL 发送 HTTP GET 请求.
I'm planning to use PHP for a simple requirement. I need to download a XML content from a URL, for which I need to send HTTP GET request to that URL.
我如何在 PHP 中执行此操作?
How do I do it in PHP?
答
除非你需要的不仅仅是文件内容,你可以使用 file_get_contents
.
Unless you need more than just the contents of the file, you could use file_get_contents
.
$xml = file_get_contents("http://www.example.com/file.xml");
对于更复杂的事情,我会使用 cURL.
For anything more complex, I'd use cURL.