我需要在服务器端发出跨域请求

发布于 2025-01-03 20:00:45 字数 255 浏览 1 评论 0原文

我有两台不同的服务器。

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

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

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

PHP 中的示例:

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

I have 2 different servers of mine.

I am using one server for managing all the data, and the system.

The other server is just for giving user points.

I need to to make a call in my first server on server side in php,
to the second server, and to get response from the server.

Example in PHP:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南街九尾狐 2025-01-10 20:00:45

你可以做这样的事情

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

you could do something like this

$response = fopen("http://otherServer.com?var1=some&var2=thing","r");
简单 2025-01-10 20:00:45

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

mysql_connect('主机1','用户名','密码')

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

You can switch between getting data from 2 servers by changing the connection to those servers like for host 1

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

execute data for host1 and save. Now when you need data from host2 connect to that and manipulate your data

还如梦归 2025-01-10 20:00:45

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

Assuming that you have a web service on your data server, you can use CURL to make HTTP requests to that service. http://php.net/manual/en/book.curl.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文