dragon19720808 2013-02-14 21:26
浏览 34
已采纳

android和两个php web服务器之间的通信[关闭]

I have two php web server ,one of them communicate with a client (android) ,I want to know how can i easily make communication between the two servers,it means how can i redirecting data, which have transfered from android, (on a web service) to the first web server,to the other web server

Just i want to mentioned that i succeed in sending data from android to the first web server so to be clear my problem is transferring automatically without human intervention data from the first web server to the second once the first web server received the data from android.
hope you'll help me with your ideas and I'm sorry for my English. Thanks a lot

  • 写回答

1条回答 默认 最新

  • dongzhi8487 2013-02-14 21:29
    关注

    Use the cURL library in PHP on the first (proxy) to make a request to the second server.

    Check out PHP cURL manual. Also see the example below. In this example I send a JSON request to a server for authentication. You can easily adapt it to send a POST request or whatever else you need:

    <?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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统