-5

I need to call a remote API using URL such http://api.remote-server.com/rest/?method=add_user&api_key=123&value=value1. If I paste this url directly in my browser url barre this work well. What I would like is simply call this url through a php file such myscript.php.

I'm not a php coder and I made some search about but did not find how to do (and especially how to search for such basic case). I tried for example this:

    <?php
    header("http://api.remote-server.com/rest/?method=add_data&api_key=12345&value=value1");
    exit;
    ?>

but this don't work. Any clue ?

dotcom27
  • 1
  • 1
  • 2
  • 5
  • 1
    You don't say what you want to do with the output of that remote service - should it be sent verbatim to the client's browser? – fvu Dec 11 '13 at 00:55
  • Why are you trying to set a response header? – Brad Dec 11 '13 at 00:57
  • 2
    possible duplicate of [How to send a GET request from PHP?](http://stackoverflow.com/questions/959063/how-to-send-a-get-request-from-php), http://stackoverflow.com/questions/5647461/how-do-i-send-a-post-request-with-php – PeeHaa Dec 11 '13 at 01:00
  • Nice to see my question is downvoted in such manner. Using file_get_contents is disallowed on my servver because I have allow_url_fopen=0 – dotcom27 Dec 11 '13 at 01:07
  • @dotcom27 So use cURL which is also mentioned in the duplicate question's answers – Phil Dec 11 '13 at 01:57

1 Answers1

3

you can fetch the url via

<?php
   $response = file_get_contents('http://api.remote-server.com/rest/?method=add_user&api_key=123&value=value1');
?>

this way your server calls the url and saves the document in $response.

Gotschi
  • 3,175
  • 2
  • 24
  • 22