ABP Zero Ajax Request (file upload) The problem is resolved by a bad request error

Source: Internet
Author: User

Using the ABP framework, the zero module is used. Then use the element UI to upload the image. A "Request for error" occurred.

It works correctly when transmitting data to an interface using Postman.

After several twists and turns, finally found the problem is Nati token problem. https://forum.aspnetboilerplate.com/viewtopic.php?f=5&t=10025&sid=5b3ace20a25195168c29846975df630d

Because the element UI is not part of the ABP. The AJAX request he used did not contain the Antiforgery token. so the ABP framework is considered a cross-site attack request, so a 400 error is returned. In the same way, using jquery's AJAX approach to request data can be a mistake.

The postman can be requested correctly because Postman does not use the APB View page and Antiforgery token is not set. so you can upload files.

The workaround is to add X-xsrf-token to the request header.

So the question becomes, how to get Antiforgery token.

The answer is, using the ABP encapsulation method: Abp.security.antiForgery.getToken (). Https://aspnetboilerplate.com/Pages/Documents/XSRF-CSRF-Protection

ABP Zero Ajax Request (file upload) The problem is resolved by a bad request error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.