【发布时间】: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 有什么关系?这是您将数据发送到到的端点的响应 - 因此它也必须在该端进行修复。