英文:
Get original url from after redirect in Spring Boot
问题
有没有办法从Spring Boot中的外部服务获取原始重定向URL?例如,如果http://example.com/redirect将重定向到我的应用程序的路由http://localhost/test,我是否可以提取"http://example.com/redirect"?
英文:
Are there any ways to get original redired URL from external service in Spring Boot? for example, if http://example.com/redirect redirects to my application with route http://localhost/test, can I extract "http://example.com/redirect"?
答案1
得分: 2
Short answer: 不。
This isn't really a Spring or Java question, so I won't address that.
Any information you need should be present in your redirect URL. Typically, this is useful in scenarios where you would want to redirect a user back to a specific page after performing an action.
Say I try to access /user-profile
but I'm not logged in. I would be redirected to /login
since /user-profile
requires that a user be logged in. However, for a seamless user experience, I'd prefer to send the user back to /user-profile
after successful login.
To achieve this, I wouldn't actually redirect the user to /login
, but /login?return_to=%2Fuser-profile
. Now, when I receive the request at /login
, I look for the return_to
parameter. That tells me where the user came from, and I'm able to send them back to that location after they have successfully logged in.
英文:
Short answer: No.
This isn't really a Spring or Java question, so I won't address that.
Any information you need should be present in your redirect URL. Typically, this is useful in scenarios where you would want to redirect a user back to a specific page after performing an action.
Say I try to access /user-profile
but I'm not logged in. I would be redirected to /login
since /user-profile
requires that a user be logged in. However, for a seamless user experience, I'd prefer to send the user back to /user-profile
after successful login.
To achieve this, I wouldn't actually redirect the user to /login
, but /login?return_to=%2Fuser-profile
. Now, when I receive the request at /login
, I look for the return_to
parameter. That tells me where the user came from, and I'm able to send them back to that location after they have successfully logged in.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论