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.

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

报告相同问题?

悬赏问题

  • ¥20 怎么在stm32门禁成品上增加记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 解riccati方程组