dongya2029 2014-06-06 15:41
浏览 48

https连接传递另一台服务器

I want to do the following scenario but i dont really know if this is possible at all or what techniques i need to use:

So im using an external api to store information of my web application. Now i want to send the api request to my server which sends it to the api server maybe by using curl and wait for the response.. when i receive the response i update something at my server like insert row in mysql and send the response back to the requester

Now the api url is using https and my server is currently using http.. will this be a problem to test or do i need https also?

And how should i implement this using php? Maybe some kind of redirect? Or do i have to rebuild the whole request?

Thanks in advance

  • 写回答

2条回答 默认 最新

  • 普通网友 2014-06-09 21:26
    关注

    There are a lot of unknowns about your question that make it hard to answer, but here goes.

    You certainly don't have to offer your own application over HTTPS and you can query an HTTPS API and then deliver your own response via HTTP. I should warn you that you are inherently making the external service less secure by doing this. If you are acting as a proxy for the external service, I would suggest that you either get an SSL certificate and do it the proper way.

    The lack of details in your question make it hard to answer a specific question, but here is a small code block that should get you started:

    <?php
    
    $url = "https://service/endpoint";
    $params = array(
        'api_token' => 'mytoken',
        'param1' => 'myparam',
    );
    $url .= http_build_query($params);
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'received error: ' . curl_error($ch) . ' (code: ' . curl_errno($ch);
    } else {
        echo 'received response: ' . $result;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大