douniuta4783 2012-10-11 11:18
浏览 67
已采纳

对来自PHP客户端站点的Https POST请求做出响应

I have a central Web Site (A) which will secure with SSL.

Other Client Sites (lets say B, C, D, E .....) will connect to this site A.

Requirement is to send a HTTPS POST request to Site A from Site B (or C,D,E.....).

Request will have parameters as

WEBSITEKEY=keyvalue;

then the Site A must give a response to this request.

Response should have a essential one parameters as,

SECUREKEY=key-value-secure;
Para1=para1value;
Para2=para2value;
Para3=para3value;
Para4=para4value;

How can I implement this response part in PHP? I'm new to SSL POST and Responses.

Later Edit,

We always send requests and get the coming response. Here I need to give the response/create the response for the client request. How can I do this in PHP? I found following code..

<?php
//process the request by fetching the info
$headers = http_get_request_headers();
$result = http_get_request_body();
//do stuff with the $headers and $result variables....
//then send your response
HttpResponse::status(200);
HttpResponse::setContentType('text/xml');
HttpResponse::setHeader('From', 'Lymber');
HttpResponse::setData('<?xml version="1.0"?><note>Thank you for posting your data! We    love php!</note>');
HttpResponse::send();
?>    

is this correct for send the response from my SSL enable site to normal site?

  • 写回答

1条回答 默认 最新

  • duanjian3338 2012-10-11 17:55
    关注

    The SSL part doesn't matter; it will be handled by the Web server and PHP will receive the request as usual.

    The only thing you need to do is build your request, and to do that, you need to know the format this request is going to be in. Also, whether you need some special MIME types or whatever.

    For example let's say the answer has to be in JSON. Then it would need to be something like:

    <?php
        if (!isset($_POST['WEBSITEKEY'])) {
             // Handle error. E.g.
             Header("HTTP/1.1 400 Bad Request");
             die();
        }
    
        $websitekey = $_POST['WEBSITEKEY'];
    
        require 'yourcode.php';
    
        $response = array(
            'SECUREKEY' => md5($secret . $websitekey),
            'para1'     => date('Y-m-d H:i:s'),
            'para2'     => 'Hello world',
        );
        // Specifying charset isn't strictly necessary but may be useful.
        Header("Content-Type: application/json;charset=UTF-8");
        $data = json_encode($response);
        $len  = strlen($data);
        // Some browser/proxy/load balancer may get better performance if the
        // length is known beforehand. This also disables Chunked-Encoding, which
        // in some scenarios may give problems.
        Header("Content-Length: {$len}");
        die($data); // Ensure no more output after this..
    

    What to do with $websitekey depends completely on your application logic. Here it is concatenated to a secret salt string and used to build the response SECUREKEY, but you can do basically whatever you want to.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答