路由参数里包含斜杠时,如何使路由生效

redqd

问题描述

这里写问题描述

当请求url是
{{base_url}}/devices/666888990/sendMqtt/greenhouse/control/shade-net/open
时,不能正确的解析topics=greenhouse/control/shade-net/open,而是返回404

Route::any('/devices/{device_id}/sendMqtt/{topics}', [app\controller\devices\IndexController::class, 'sendMqtt']);
125 3 0
3个回答

你为什么不愿意修改一下路由的传参方式,或者你的参数应该避免出现/,就像你用Windows系统需要避免文件名是 \一样

  • 暂无评论
Route::any('/devices/{device_id}/sendMqtt/[{topics:.+}]', [app\controller\devices\IndexController::class, 'sendMqtt']);

这个webman路由文档有例子,这样写

  • redqd 5天前

    谢谢,谢谢,确实可行

dj880

谢谢分享~

  • 暂无评论
🔝