You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP CURL POST长字符串返回404及SSL错误问题求助

问题:PHP CURL POST长字符串失败,SSL_write()错误及优化需求

问题背景

我最近一周一直在折腾PHP CURL发送POST请求的问题——只要请求里包含长字符串(比如140万字符)就会失败。一开始我以为是Expect: 100-continue机制的问题,特意添加了Expect:头来规避,但还是没解决这个问题。

我的代码

发送请求脚本(send_request.php)

$array = array( 
    'value' => $short_string, // 少于1024字符
    'long_value' => $long_string, // 超过1024字符(实际是1400000字符)
);
$array = http_build_query($array);
$headers = array('Expect:');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://domain_name.com/url/to/script.php');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $array);
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$error = curl_error($ch);
$info = curl_getinfo($ch);
curl_close($ch);

接收请求脚本(process_request.php)

if($_SERVER['REQUEST_METHOD'] == 'POST'){
    $response = 'okay short string';
    if(isset($_POST['long_value'])){
        $response = 'okay long string';
    }
    echo $response;
}

当前现象

  • 仅发送短字符串时:完全正常,无错误,能收到返回的okay short string
  • 发送长字符串或长短混合字符串时:curl_error()返回SSL_write() returned SYSCALL, errno=0,而且curl_exec()拿到的是目标URL的404页面,根本没走到接收脚本的逻辑里

注:$long_string是本地数据库查询结果经json_encode后,再用AES-256-CBC加密得到的内容

已尝试的临时方案(但不够理想)

我移除了$array = http_build_query($array)这一行,直接发送json_encode后未加密的数据,请求能成功了,但耗时将近4分钟,速度实在太慢。现在想寻求更高效的解决办法。

内容的提问来源于stack exchange,提问作者molinet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:42:21