413 PHP错误

时间:2012-05-14 02:30:54

标签: php curl

我正在通过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文件,但这太大了。我愿意接受任何建议!提前谢谢!

1 个答案:

答案 0 :(得分:1)

413是'请求实体太大'。您是否尝试将HTTP标头填充到POSTFIELDS部分?如果这个服务不期望任何帖子字段(例如正文应该是0字节),那么使用POSTFIELDs发送你的“标题”肯定会将其设置为关闭。对于headeres,您应该使用CURLOPT_HTTPHEADER而不是