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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog