/api/wechat/login 可以正常访问/api/wechat/case/stepCode/dealings 无法到达后端问题:除了登录接口外,所有 /wechat/** 路径都需要JWT token认证。
检查方法:
解决方案:
Authorization 字段HDU xxxxxx(根据JWT配置)问题:ngrok可能配置了路径重写或只转发特定路径。
检查ngrok配置:
# 检查ngrok配置文件(通常在用户目录下的.ngrok2/ngrok.yml)
# 或者查看启动ngrok时的命令参数
正确的ngrok配置应该是:
# ngrok.yml 示例
tunnels:
backend:
addr: 8080 # 后端服务端口
proto: http
# 不要设置 bind_tls 或 path 参数,除非你确定需要
启动命令应该是:
ngrok http 8080
# 或者
ngrok http localhost:8080
错误的配置示例(会导致路径问题):
# ❌ 错误:如果设置了路径重写
ngrok http 8080 --host-header=rewrite
# 或者配置了 path 参数
当前配置:
context-path: /api(在application-dev.yaml中)/api/xxx完整路径映射:
http://ngrok域名/api/wechat/login ✅http://ngrok域名/api/wechat/case/stepCode/dealings ✅检查点:
测试方法:
# 直接测试本地后端(绕过ngrok)
curl -X GET "http://localhost:8080/api/wechat/case/stepCode/dealings?stepCode=500" \
-H "Authorization: HDU your-token-here"
# 测试ngrok转发
curl -X GET "http://your-ngrok-domain.ngrok-free.dev/api/wechat/case/stepCode/dealings?stepCode=500" \
-H "Authorization: HDU your-token-here"
查看后端控制台日志,看是否有:
确保请求包含:
Authorization: HDU xxxxxx
Content-Type: application/json
绕过ngrok,直接访问本地接口:
# 使用Postman或curl测试
GET http://localhost:8080/api/wechat/case/stepCode/dealings?stepCode=500
Headers:
Authorization: HDU your-token-here
在ngrok的Traffic Inspector中:
已在拦截器中添加了详细的日志,重启后端后可以看到:
如果需要测试,可以临时注释掉拦截器配置:
// 在 WebMvcConfiguration.java 中临时注释
// registry.addInterceptor(jwtTokenUserInterceptor)
// .addPathPatterns("/wechat/**")
// .excludePathPatterns("/wechat/login")
// .excludePathPatterns("/wechat/loginTest","/wechat/esign/callback")
// .excludePathPatterns("/wechat/file/download/**");
注意:测试完后记得恢复!
如果ngrok显示请求成功(200),但后端没有日志,可能是:
已在项目中添加了 RequestLoggingFilter,它会:
拦截器现在会记录:
# Windows PowerShell
netstat -ano | findstr :8080
# 应该看到类似输出:
# TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 12345
如果看不到8080端口在监听,说明后端应用没有启动或启动失败。
使用Postman或curl直接测试本地接口:
# 测试登录接口(不需要token)
curl -X POST "http://localhost:8080/api/wechat/login" \
-H "Content-Type: application/json" \
-d "{\"code\":\"test\"}"
# 测试问题接口(需要token)
curl -X GET "http://localhost:8080/api/wechat/case/stepCode/dealings?stepCode=500" \
-H "Authorization: HDU your-token-here"
如果本地测试也失败,说明是后端应用本身的问题,不是ngrok的问题。
# 检查ngrok是否正在运行
# 在ngrok的web界面查看:http://localhost:4040
# 检查ngrok转发的目标
# 应该显示:Forwarding https://xxx.ngrok-free.dev -> http://localhost:8080
重要检查点:
http://localhost:8080 或 http://127.0.0.1:8080)查看启动日志,确认:
发送测试请求(通过ngrok)
查看日志输出:
在 http://localhost:4040 查看:
请求是否出现在列表中?
查看请求详情:
Authorization 头?200 → 请求成功,检查响应内容401 → 认证失败,检查token404 → 路径不存在,检查URL502 Bad Gateway → ngrok无法连接到后端504 Gateway Timeout → 后端响应超时查看Response:
ngrok免费版可能会:
解决方案:
ngrok-skip-browser-warning: true# Windows防火墙可能阻止了8080端口
# 检查Windows防火墙设置,确保8080端口允许入站连接
可能原因:
解决方案:
可能原因:
解决方案:
/wechat/** 模式可能原因:
解决方案:
Authorization 值HDU xxxxxx(注意有空格)可能原因:
解决方案:
127.0.0.1:8080 而不是 localhost:8080如果问题仍未解决,请提供: