代碼如下:
<?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;
});
};
// 運(yùn)行worker
Worker::runAll();
百度返回的內(nèi)容是
<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://"));
導(dǎo)致瀏覽器不停的刷新,然后再次返回相同的內(nèi)容,再次刷新。。。具體為什么百度返回的是刷新,可能和某個(gè)http頭有關(guān)系。