workerman的异步http-client怎么在onMessage回调中不生效,浏览器无限刷新

avriltank

代码如下:

<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
require_once __DIR__ . '/vendor/autoload.php';

$worker = new Worker('http://0.0.0.0:9898');

$worker->onWorkerStart = function()
{
    global $http_client;
    $http_client = new Workerman\Http\Client();
};

$worker->onMessage = function(TcpConnection $connection, Request $request)
{
    global $http_client;
    $http_client->get('https://www.baidu.com', function (\Psr\Http\Message\ResponseInterface $response) use($connection){
        $message = $response->getBody()->__toString();
        $connection->send($message);
    }, function ($exception) {
        echo $exception;
    });
};

// 运行worker
Worker::runAll();
1006 1 0
1个回答

walkor 打赏

百度返回的内容是

<html>
<head>
    <script>
        location.replace(location.href.replace("https://","http://"));
    </script>
</head>
<body>
    <noscript><meta http-equiv="refresh" content="0;url=http://www.baidu.com/"></noscript>
</body>

location.replace(location.href.replace("https://","http://"));导致浏览器不停的刷新,然后再次返回相同的内容,再次刷新。。。具体为什么百度返回的是刷新,可能和某个http头有关系。

  • avriltank 2022-07-11

    懂了,谢谢群主,没注意看返回代码。。.

年代过于久远,无法发表回答
×
🔝