【问题标题】:PHP CURL - BAD REQUEST POST - WHEN POSTFIELDS IS VERY BIGPHP CURL - 错误的请求发布 - 当 POSTFIELDS 非常大时
【发布时间】:2018-03-11 10:19:57
【问题描述】:

我正在使用 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
        );
    }

【问题讨论】:

  • 您的 CAPS LOCK 在不应该打开时打开
  • 这和 cURL 有什么关系?这是您将数据发送到的端点的响应 - 因此它也必须在该端进行修复。

标签: php curl post


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-12-06
    • 2022-11-29
    • 2017-11-21
    • 2020-04-26
    • 1970-01-01
    • 2017-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多