PHP 8.2中Curl请求文件下载时出现OpenSSL SSL_read错误求助
PHP 8.2.5下CURL请求文件下载时出现SSL读取错误
该问题与PHP bug #79589相关,但使用PHP 8.2.5时已有的修复无效,也未找到其他可行解决方案。
通过POST请求某URL,提交不同参数会返回两种结果:HTML响应或文件下载(带有Content-Disposition: attachment;...响应头)。请求HTML输出时数据正常,但指定文件下载选项时出现以下CURL错误:
OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0
推测问题与文件下载特性相关,可能是服务器返回文件时未提供Content-Length头,但无法控制服务器端配置。
代码在PHP 7.4.2等旧版本中运行正常,但因需求必须使用最新版本,暂未确定代码失效的最高PHP版本。
成功请求(HTML)日志示例
* Trying XXX:443... * Connected to XXX.com (XXX) port 443 (#0) * ALPN: offers http/1.1 * CAfile: D:\Certs\cacert.pem * CApath: none * SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384 * ALPN: server accepted http/1.1 * Server certificate: * subject: XXX * start date: Jun 1 10:25:49 2022 GMT * expire date: Jun 29 10:25:49 2023 GMT * subjectAltName: host "XXX.com" matched cert's "XXX.com" * issuer: C=US; O=Entrust, Inc.; OU=See www.entrust.net/legal-terms; OU=(c) 2012 Entrust, Inc. - for authorized use only; CN=Entrust Certification Authority - L1K * SSL certificate verify ok. > POST /XXX.asp HTTP/1.1 Host: XXX.com Accept: */* Cookie: XXX Content-Type: application/x-www-form-urlencoded Content-Length: 446 * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Cache-Control: private,private < Content-Type: text/html < Expires: Tue, 02 May 2023 12:30:36 GMT < Server: Microsoft-IIS/10.0 * Replaced cookie XXX for domain XXX.com, path /, expire 0 < Set-Cookie: XXX; secure; path=/ < X-Powered-By: ASP.NET < X-Frame-Options: SAMEORIGIN < Date: Wed, 03 May 2023 12:30:36 GMT < Content-Length: 20260 < * Connection #0 to host XXX.com left intact
失败请求(文件下载)日志示例
* Trying XXX:443... * Connected to XXX.com (XXX) port 443 (#0) * ALPN: offers http/1.1 * CAfile: D:\Certs\cacert.pem * CApath: none * SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384 * ALPN: server accepted http/1.1 * Server certificate: * subject: XXX * start date: Jun 1 10:25:49 2022 GMT * expire date: Jun 29 10:25:49 2023 GMT * subjectAltName: host "XXX.com" matched cert's "XXX.com" * issuer: C=US; O=Entrust, Inc.; OU=See www.entrust.net/legal-terms; OU=(c) 2012 Entrust, Inc. - for authorized use only; CN=Entrust Certification Authority - L1K * SSL certificate verify ok. > POST XXX.asp HTTP/1.1 Host: XXX.com Accept: */* Cookie: XXX Content-Type: application/x-www-form-urlencoded Content-Length: 446 * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Cache-Control: private,private < Content-Type: text/x-oasis-csv < Expires: Tue, 02 May 2023 12:32:14 GMT < Server: Microsoft-IIS/10.0 < Content-Disposition: attachment; filename=20230503083225ED.csv * Replaced cookie XXX for domain XXX.com, path /, expire 0 < Set-Cookie: XXX; secure; path=/ < X-Powered-By: ASP.NET < X-Frame-Options: SAMEORIGIN < Date: Wed, 03 May 2023 12:32:25 GMT < Connection: close < * OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0 * Closing connection 0
内容的提问来源于stack exchange,提问作者MJC
相关产品推荐
相关产品推荐

