如何从 PHP 发送 GET 请求? [英] How to send a GET request from PHP?

查看:28
本文介绍了如何从 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.

这篇关于如何从 PHP 发送 GET 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆