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 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图