POST 请求需要 Laravel 中的 Content-length 标头

c31*_*113 1 http-headers laravel

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

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

411. That’s an error.

POST requests require a Content-length header. That’s all we know.
Run Code Online (Sandbox Code Playgroud)

我尝试在中间件文件夹中添加头文件,但似乎没有任何效果。我发现 Laravel 中不包含 Content-length 标头(我认为不太确定)所以我将如何添加它请注意我对 Laravel 很陌生

c31*_*113 7

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

$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;
Run Code Online (Sandbox Code Playgroud)