How to send a GET request from PHP? How to send a GET request from PHP? php php

How to send a GET request from PHP?


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");

For anything more complex, I'd use cURL.


For more advanced GET/POST requests, you can install the CURL library (http://us3.php.net/curl):

$ch = curl_init("REMOTE XML FILE URL GOES HERE"); // such as http://example.com/example.xmlcurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_HEADER, 0);$data = curl_exec($ch);curl_close($ch);


http_get should do the trick. The advantages of http_get over file_get_contents include the ability to view HTTP headers, access request details, and control the connection timeout.

$response = http_get("http://www.example.com/file.xml");