如何在php文件中调用url


How to call an url in php file?

我需要使用URL调用远程APIhttp://api.remote-server.com/rest/?method=add_user&api_key=123&value=value1.如果我把这个url直接粘贴到我的浏览器url barre中,效果会很好。我想要的只是通过一个php文件(比如myscript.php.)来调用这个url

我不是php程序员,我搜索了一些,但没有找到如何做(尤其是如何搜索这样的基本情况)。我举了一个例子:

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

但这行不通。有线索吗?

您可以通过获取url

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

通过这种方式,您的服务器调用url并将文档保存在$response中。