0

I am needing to write a very basic PHP document that makes an API GET call through XML. The response will yield xml data with an id tag. I then need to take that tag and make a custom XML response that takes data within the id tag. I have done a lot of reading but am really confused at how to make this simple HTTP Get request using PHP

Here is the request I need to make:

GET https://api.example.com HTTP/1.1 
Authorization: TOK:12345678-1234-1234-1234-1234567890ab 
Accept: application/xml 
Host: api.example.com 

Here is the response I need to pass along in this xml response

<channels>
    <channel name="channelname">
        <rtmp>rtmp://example.com</rtmp>
        <stream>live?IDREQUESTEDTAGGOESHERE</stream>
    </channel>
</channels>
Seth Haberman
  • 131
  • 1
  • 11
  • Your question is a bit unlcear. Material on how to send a HTTP GET request in PHP with headers does exist (I used some of that material to mark your question as duplicate). If you also look explicitly about how to send a HTTP request body (which might be what you ask in the XML part), then take a look here specifically: [HTTP GET with request body](http://stackoverflow.com/q/978061/367456). If you have problems to understand how HTTP works independet to PHP, you find an introduction on Wikipedia: http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol. - And why the JSON tag? – hakre Jun 06 '14 at 06:11
  • I looked at your linked thread but with that example I do not see a URL where the GET called is being made to. Will that echo the response from the API? – Seth Haberman Jun 06 '14 at 06:23
  • URL is `http://www.example.com/`, the line of code in the lined duplicate's answer is: `$file = file_get_contents('http://www.example.com/', false, $context);`. It does not echo, but stores the result into `$file` which you then can error-check and further process, see the documentation of [`file_get_contents()`](http://php.net/file_get_contents). See as well http://stackoverflow.com/questions/how-to-ask – hakre Jun 06 '14 at 08:45

0 Answers0