2012-05-14 54 views
0

我通過cURL發送HTTP請求,我不斷收到此413錯誤。我試圖發送的文件位於21kb,我檢查了我的php.ini文件。有人能告訴我什麼是錯的嗎?413錯誤與PHP

這裏是我的代碼,直接影響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文件,但這是太大了。我願意接受任何建議!先謝謝你!

+0

發送少量數據。或者,向另一方詢問可以發送多少數據。 –

回答

1

413是'請求實體太大'。您試圖將HTTP標頭填入POSTFIELDS部分的任何原因?如果這個服務沒有期望任何post字段(例如body應該是0字節),那麼使用POSTFIELDs發送你的「標題」將肯定會設置它。對於headeres,您應該使用CURLOPT_HTTPHEADER而不是