【问题标题】:I need to make cross domain requests server side我需要在服务器端进行跨域请求
【发布时间】:2012-07-03 22:26:25
【问题描述】:

我有 2 个不同的服务器。

我正在使用一台服务器来管理所有数据和系统。

另一台服务器只是为了给用户积分。

我需要在服务器端的第一台服务器上调用 php, 到第二台服务器,并从服务器获取响应。

PHP 中的示例:

$response = getDataFromOtherServer("http://otherServer.com");
// manipulate response

【问题讨论】:

  • 你可以访问两台服务器吗?

标签: php cross-domain


【解决方案1】:

你可以这样做

$response = fopen("http://otherServer.com?var1=some&var2=thing","r");

【讨论】:

    【解决方案2】:

    您可以通过更改与主机 1 等服务器的连接来在从 2 个服务器获取数据之间切换

    mysql_connect('host1','username','password')

    为 host1 执行数据并保存。现在,当您需要来自 host2 的数据时,连接到该主机并操作您的数据

    【讨论】:

      【解决方案3】:

      使用 Phil Sturgeon 的 REST API ->

      休息服务器: https://github.com/philsturgeon/codeigniter-restserver

      REST 客户端: https://github.com/philsturgeon/codeigniter-restclient

      【讨论】:

        【解决方案4】:

        假设您的数据服务器上有一个 Web 服务,您可以使用 CURL 向该服务发出 HTTP 请求。 http://php.net/manual/en/book.curl.php

        【讨论】:

          猜你喜欢
          • 2018-03-02
          • 2014-07-23
          • 2012-04-18
          • 2017-06-06
          • 2012-10-24
          • 1970-01-01
          • 2018-12-05
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多