gpt4 book ai didi

laravel - POST 请求在 laravel 中需要 Content-length header

转载 作者:行者123 更新时间:2023-12-05 08:54:36 25 4
gpt4 key购买 nike

       $output = Curl::httpGet("https://bhleh.com/emailstorage",  "POST", $params);                    
return $output;

这是在我的 laravel 中,但每当我尝试运行它时,我都会收到一条错误消息

411. That’s an error.

POST requests require a Content-length header. That’s all we know.

我尝试在我的中间件文件夹中添加头文件,但似乎没有任何效果。我发现 Content-length header 不包含在 laravel 中(我想不太确定)所以我该如何添加它请注意我是 laravel 的新手

最佳答案

这个修复是我用这个替换了整个代码

$data_string = json_encode($params);                                                                                                                                                                                                                   
$ch = curl_init('https://bhleh.com/emailstorage');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);

$result = curl_exec($ch);
return $result;

关于laravel - POST 请求在 laravel 中需要 Content-length header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49229524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com