国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

響應頭和設置的頭信息不一致

原地起飛

問題描述

代碼里面設置的 Transfer-Encoding:chunked
這里寫問題描述

截圖

        $ask = $request->input('ask');
        if(!$ask){
            return json(['code' => 1005,'msg' => '缺少必要參數(shù)']);
        }
        $apikey = '';
        $secretKey = '';
        $traceId = uniqid();//'A9AB29036A9D4E05545116DA32123dsf2';
        $timestamp = time();
        $url = 'xxxx' . $apikey;
        $http = new \Workerman\Http\Client();
        $connection = $request->connection;
        $bufferSend = new Response(200, ['Content-Type' => 'text/event-stream'],"\r\n");
        $connection->send($bufferSend,true);
        $data = [
            'traceId' => $traceId,
            'timestamp' => $timestamp,
            'stream' => true,
            'messages' => [
                [
                    'content' => $ask,
                    'role' => 'user'
                ]
            ],

        ];

        $http->request($url, [
            'method' => 'POST',
            'data' => json_encode($data),
            'headers' => [
                'Content-Type' => 'application/json',
                'App-Sign' => $this->makeXcSign($apikey,$secretKey,$traceId,$timestamp),
            ],
            'progress' => function($buffer) use ($connection) {
                $connection->send($buffer, true);
            },
            'success' => function($response) use ($connection) {
                $connection->send(new Chunk(''));
                $connection->close();
            },
        ]);

        return (new Response(200, [
            "Transfer-Encoding" => "chunked",
        ]));
694 2 0
2個回答

walkor 打賞

根據(jù)你的代碼,http頭是這塊的代碼發(fā)送的

$connection = $request->connection;
$bufferSend = new Response(200, ['Content-Type' => 'text/event-stream'],"\r\n");
$connection->send($bufferSend,true);
  • 原地起飛 2024-06-13

    我這邊寫到上面就不輸入內(nèi)容了,這個是什么原因呀

  • walkor 2024-06-13

    因為你發(fā)送了兩個http頭,是錯誤用法。

    $bufferSend = new Response(200, ['Content-Type' => 'text/event-stream'],"\r\n");
    $connection->send($bufferSend,true);

    這段去掉

  • 原地起飛 2024-06-13

    去掉的話就不是這個event-stream了

  • 原地起飛 2024-06-13

    加在下面的話報錯

  • 原地起飛 2024-06-13

    能不能讓content-type和這個Transfer-Encoding都改了呢

原地起飛

截圖
改了后流數(shù)據(jù)沒返回
截圖

??