简体   繁体   中英

Get file from a URL using GET request?

I have to make a get request to a url to download a xml file hourly. I am changing my code over to php.

in the past the code was :

Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")


oXMLHTTP.Open "GET", "http://api.sportsdatallc.org/golf-t1/leaderboard/pga/2012/tournaments/" & currentidString & "/leaderboard.xml?api_key="given key id", False
oXMLHTTP.Send

If oXMLHTTP.Status = 200 Then
    Set oStream = CreateObject("ADODB.Stream")
    oStream.Open
    oStream.Type = 1
    oStream.Write oXMLHTTP.responseBody
    oStream.SaveToFile "file.xml", 2
    oStream.Close
End If

how can I do this using php? I am confused because of all the extra lines for http.

I think you can use:

$xml = file_get_contents("http://api.sportsdatallc.org/golf-t1/leaderboard/pga/2012/tournaments/" & currentidString & "/leaderboard.xml?api_key="given key id");

or you can use the curl library for more advanced requests

http://www.php.net/curl

I hope this help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM