android和两个php web服务器之间的通信

时间:2013-02-14 21:26:41

标签: php

我有两个php web服务器,其中一个与客户端(android)通信,我想知道如何轻松地在两个服务器之间进行通信,这意味着怎么能我将已从Android (在Web服务上)转移到第一个Web服务器的数据重定向到到另一个Web服务器

我想提一下,我成功地将数据从Android发送到第一个Web服务器,所以要清楚我的问题是自动传输 而无需人为干预 来自一旦第一个Web服务器从android接收到数据,第一个Web服务器到第二个 希望你能帮我解决你的想法,对不起我的英语。 非常感谢

1 个答案:

答案 0 :(得分:0)

在第一个(代理)上使用PHP中的cURL库向第二个服务器发出请求。

结帐PHP cURL manual。另请参阅下面的示例。在此示例中,我向服务器发送JSON请求以进行身份​​验证。您可以轻松地对其进行调整以发送POST请求或您需要的任何其他内容:

<?php

$fld = array(
    'registration_ids' => array('1234'),
    'data' => array('header' => 'abc', 'message' => 'def'));
$hdr = array(
    'Content-Type: application/json',
    'Authorization: key=ghi');

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://example.com:9777');
curl_setopt($ch, CURLOPT_PORT, 9777);
curl_setopt($ch, CURLOPT_HTTPHEADER, $hdr);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fld));

$response = curl_exec($ch);
curl_close($ch);