问题描述

在使用 curl 进行请求时,第一次请求超时,第二次请求成功返回。第一次请求中,curl 尝试向服务器发送一个较大的 JSON 数据,但由于防火墙或 GFW 屏蔽,导致请求无法成功完成。


代码表现

root@free:~# curl -v --max-time 30 http://local.domain.com:8890/gamebox/atomicTool/executeById/28 \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ak_a32a3bd53c603e836bd7f7" \
    -d @tmp.json
*   Trying 182.119.xxx.xxx:8890...
* Connected to local.domain.com (182.119.xxx.xxx) port 8890 (#0)
> POST /gamebox/atomicTool/executeById/28 HTTP/1.1
> Host: local.domain.com:8890
> User-Agent: curl/7.81.0
> Accept: */*
> Content-Type: application/json
> Authorization: Bearer ak_a32a3bd53c603e836bd7f7domain.com
> Content-Length: 2314053
> Expect: 100-continue
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 
* Operation timed out after 30000 milliseconds with 0 bytes received
* Closing connection 0
curl: (28) Operation timed out after 30000 milliseconds with 0 bytes received
root@free:~# ^C
root@free:~# ^C
root@free:~# ^C
root@free:~# curl -v --max-time 30 http://local.domain.com:8890/gamebox/atomicTool/executeById/28 \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ak_a32a3bd53c603e836bd7f7" \
    -d {}
* Connected to local.domain.com (182.119.xxx.xxx) port 8890 (#0)
> POST /gamebox/atomicTool/executeById/28 HTTP/1.1
> Host: local.domain.com:8890
> User-Agent: curl/7.81.0
> Accept: */*
> Content-Type: application/json
> Authorization: Bearer ak_a32a3bd53c603e836bd7f7domain.com
> Content-Length: 2
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: SAMEORIGIN
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Thu, 30 Apr 2026 18:31:30 GMT
< 
* Connection #0 to host local.domain.com left intact
{"msg":"操作成功","code":200,"data":{"output":{"success":false,"message":"JSON 数据不能为空"},"message":"执行成功","status":"success"}}
root@free:~# ^C
root@free:~# 

分析

  • 第一次请求:由于防火墙或 GFW 屏蔽,导致请求超时,curl 报告 (28) Operation timed out
  • 第二次请求:发送了一个空的 JSON {},请求成功,服务器返回状态 200,并给出错误信息 JSON 数据不能为空

问题总结

  • 可能的原因是 出网防火墙GFW 屏蔽 导致无法正常请求,导致第一次请求超时。
  • 第二次请求的数据较小,服务器成功处理,因此返回了正常的响应。

解决方案思路

  1. 检查并配置防火墙,确保出站连接不被阻止。
  2. 如果受到 GFW 屏蔽,尝试通过 VPN 或代理解决。
  3. 增加请求超时时间,避免因响应延迟导致的超时。
最后修改:2026 年 05 月 01 日
反正没人给,你也爱给不给吧。