http-client 协程请求302重定向的链接无响应

Jason X

问题描述

协程下似乎请求重定向的接口会无响应,测试请求非重定向的接口正常,不使用协程方式也请求正常

程序代码或配置

$requestOption = [
    "method" => "GET",
    'version' => '1.1',
    'headers' => [
        'X-Forwarded-For' => $ip,
        'User-Agent' => $ua,
        'Connection' => 'keep-alive'
    ],
    'allow_redirects' => [
        'max' => 10
    ],
    //'success' => function ($response) {
        //return $response->getBody();
    //    return $response;
    //},
    'error' => function ($exception) {
        return $exception;
    }
];
try{
    //$tracingUrl = "https://www.workerman.net/";
    $requestRs = $this->coroutineHttp->request(trim($tracingUrl),$requestOption);
    $rrs = $requestRs->getStatusCode();
    //$rrs = $requestRs;
}catch (\Exception $e) {
    $this->logger->info("Test caught exception:". $e->getMessage());
    $rrs = $e->getMessage();
} catch (\Throwable $e) {
    $this->logger->info("Test caught exception:". $e->getMessage());
    $rrs = $e->getMessage();
}

操作系统环境及workerman/webman等具体版本

"workerman/workerman": "^5.0.0",
"revolt/event-loop": "^1.0.0",
"workerman/http-client": "^2.2.8"

22 1 0
1个回答

Jason X

找到个问题点。$options是复制的变量,$task是后置引用修改的,导致302重新建立请求对象时丢失了success回调,补上引用应该就解决了。
截图
截图
截图

$options['success'] = $task['options']['success'] ?? null;
$options['error'] = $task['options']['error'] ?? null;
  • 暂无评论
×
🔝