PHP CURL - BAD请求发布 - 当后场非常大时

时间:2017-09-29 13:38:55

标签: php curl post

我正在发送一个带有CURL PHP API的POST请求,当POSTFIELDS很小时没有问题,但是当POSTFIELDS非常大时,它会响应错误400" BAD POST CONTENT"。

try {

        $header  = array(
            "content-type: application/json",
        );

        $direccionService = $direccion.":".$puerto."/".$direccionService.$operacion;
        // PREPARE THE CURL CALL
        $curl = curl_init();
        curl_setopt( $curl, CURLOPT_URL,            $direccionService);
        curl_setopt( $curl, CURLOPT_HEADER,         FALSE);
        curl_setopt( $curl, CURLOPT_HTTPHEADER,     $header);
        curl_setopt( $curl, CURLOPT_POST,           TRUE);
        curl_setopt( $curl, CURLOPT_POSTFIELDS,     json_encode($dataF));
        curl_setopt( $curl, CURLOPT_TIMEOUT,        100);
        curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt( $curl, CURLOPT_COOKIEFILE,     "cookie".$Nit);

        $response = curl_exec($curl);
        $err = curl_error($curl);
        $inf = curl_multi_getcontent($curl);

        curl_close($curl);

        $array = array();
        $res = '';
        if ($err) {
            $res = array(
            "error" => "Sintaxis Erronea solicitud",
            "code" => "400",
            "message" => "Curl Error -". $err
            );
        } else {
            $res = $response;
        }
    } catch (Exception $e) {
        $res = array(
           "error" => "Exception",
           "code" => "406",
           "message" => "Exception -". $e
        );
    }

1 个答案:

答案 0 :(得分:0)

这是一个错误。当有效负载太大时,它不应该响应400 Bad Request,它应该响应413 Payload Too Large。联系端点维护人员并让他们知道。

相关问题