Problem Description:
When we test the Web API with the Swagger UI times 401 Error
Let's open the Get/api/services/app/role/getall, enter the parameters.
Click the Try it out! button to report 401 errors
Causes and Solutions
See an icon with a red exclamation mark in the upper-right corner
Click to view the reason is that the Access API needs to enter the authorization token value for verification, token value is the background based on the user dynamically generated, how to get it?
Solution, we can directly log in to the client to view the token value of the Access API
After I login successfully with admin, F12 Check the background token value of the browser and click on the link of request data to background request API under Network (NOTE: I use Google Chrome)
We found the authorization token information in the headers request headers inside the authorization.
Bearer Eyjhbgcioijiuzi1niisinr5cci6ikpxvcj9.eyjodhrwoi8vc2nozw1hcy54bwxzb2fwlm9yzy93cy8ymda1lza1l2lkzw50axr5l2nsywltcy9uyw1lawrl Bnrpzmllcii6ijiilcjodhrwoi8vc2nozw1hcy54bwxzb2fwlm9yzy93cy8ymda1lza1l2lkzw50axr5l2nsywltcy9uyw1lijoiywrtaw4ilcjbc3bozxqus Wrlbnrpdhkuu2vjdxjpdhltdgftcci6ijy3ndhlndq2lti4ywutywrjni0znmu2ltm5ztizmgfhnza3msisimh0dha6ly9zy2hlbwfzlm1py3jvc29mdc5jb2 0vd3mvmjawoc8wni9pzgvudgl0es9jbgfpbxmvcm9szsi6ikfkbwluiiwiahr0cdovl3d3dy5hc3buzxrib2lszxjwbgf0zs5jb20vawrlbnrpdhkvy2xhaw1 zl3rlbmfudelkijoimsisinn1yii6ijiilcjqdgkioii0n2u0y2ywnc05odyyltq4mjitotbhoc01njk1nwuwywe1m2uilcjpyxqioje1mte0ndu3mjusim5i Zii6mtuxmtq0ntcynswizxhwijoxntexntmymti1lcjpc3mioijzywfziiwiyxvkijoic2fhcyj9.exdes4lnkv4dkcfy-gtsf6kgdtk3a0bls3i6o7c2huq
Copy this authorization information to our backstage to authorize
Point development is now authorized to succeed
Then we test again, Response code has returned 200, and the test passed. Debug in the background break point
ABP with Swagger UI Test API report 401 No access problem