When springboot + shiro downloads files, the browser prompts "unable to download-no permission" or "unable to download-no file" problem

When springboot + shiro downloads files, the browser prompts "unable to download-no permission" or "unable to download-no file" problem

1. Expected effect

The back-end writes the file download interface, and the front-end saves the file locally through the download of the browser.

2. Problem description

The front-end and back-end codes run on different hosts. The back-end uses the postman test download interface to download files normally, but the file browser will prompt "Unable to download-no permission" or "Unable to download-no file" when downloading files on the front-end.

3. Troubleshooting

  • The front-end triggered download did not enter the breakpoint of the back-end download interface. It is guessed that it may be related to the shiro framework used by the back-end.
  • Release the requested url in the shiro framework, and the front end can download the file normally, indicating that the problem is related to shiro.
  • In the debug of the relevant code of the shiro framework, it is found that when the front-end triggers the download, the executeLogin method cannot obtain the token of the request body, so the front-end download request is intercepted and returned without entering the back-end download interface.

4. Solutions

  • Check whether the token information has been passed to the front end? What is the method?
  • Check how executeLogin obtains token information? Does it match the way the front end works?

5. Summary

The key point of this problem is that the shiro framework will authenticate the front-end request. As long as the front-end passes the identity authentication information such as token, the back-end can receive it normally, and the front-end request can enter the back-end interface normally.

Guess you like

Origin blog.csdn.net/qq_45256357/article/details/132038276