0

我正在通过 cURL 发送 HTTP 请求,并且不断收到此 413 错误。我要发送的文件是 21kb,我检查了我的 php.ini 文件。有人可以告诉我有什么问题吗?

这是我直接影响 HTTP 请求的代码:

    <?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Class for creating test cases to be sent 
 * into TestRail
 * @author Banderson
 */
class testCase {

    /*Function to get the data for each individual test case*/
    function getTestCase($row, $highestColIndex, $PHPobjWorksheet){

            echo "<br />";
            for($col=0;$col<=$highestColIndex;++$col){
                $v=$PHPobjWorksheet->getCellByColumnAndRow($col,$row)->getValue();
                $cellValue[]=$v;



        }

    return $cellValue;

    }


    /*Function to set the data for each individual test case*/
    function setTestCase($cellValue){
                $case[]=array();
                $case['title'] = $cellValue[0];
                echo $case['title']. "<- Title"."<br/>";
                $case['type'] = $cellValue[1];
                echo $case['type']. "<- Type"."<br/>";
                $case['priority'] = $cellValue[2];
                echo $case['priority']. "<- Priority"."<br/>";


                /*$case['estimate'] = $cellValue[3];
                echo $case['estimate']. "<- Estimate"."<br/>";
                $case['milestone'] = $cellValue[4];
                echo $case['milestone']. "<- MileStone"."<br/>";
                $case['refs'] = $cellValue[5];
                echo $case['refs']. "<- Custom Refs"."<br/>";
                $case['precon'] = $cellValue[6];
                echo $case['precon']. "<- Custom Precondition"."<br/>";
                $case['steps'] = $cellValue[7];
                echo $case['steps']. "<- Custom Steps"."<br/>";
                $case['expectedresults'] = $cellValue[8];
                echo  $case['expectedresults']. "<- Expected Results"."<br/>";
                $case['testSuite'] = $cellValue[9];
                echo $case['testSuite']. "<- TestSuite"."<br/>";*/


                $caseData=array(

                    'Title'=> $case['title'],
                    'Type'=> $case['type'],
                    'Priority'=> $case['priority'],
                    'key'=> "246810",


                );

                return $caseData;


    }

    function sendTestCase($caseArgs){
        try{
            $ch = curl_init();
            //$sendData = http_build_query($caseArgs);

            $header=array();
            $header[]= "Accept: application/json";

            $header[]= "Host: localhost";
            $header[]= "Title=newTitle";
            $header[]= "key=2467810";



            curl_setopt($ch, CURLOPT_URL, 'http://localhost:8888/testrail/index.php?/miniapi/add_case/2');  
            curl_setopt($ch, CURLOPT_POSTFIELDS, $header);
            curl_setopt($ch, CURLOPT_POST, 1);



            curl_exec($ch);
            curl_close($ch);
        }
        catch (HttpException $ex){
            echo $ex."<-Exception";
 }


    }

}

?>

我会包含我的 php.ini 文件,但这太大了。我愿意接受任何建议!先感谢您!

4

1 回答 1

1

413 是“请求实体太大”。您尝试将 HTTP 标头填充到 POSTFIELDS 部分的任何原因?如果此服务不需要任何 post 字段(例如 body 应该是 0 字节),那么使用 POSTFIELDs 发送您的“标题”肯定会关闭它。对于标题,您应该CURLOPT_HTTPHEADER改用

于 2012-05-14T02:41:42.473 回答