Why is 405 returned when yii2 generates a URL?

Source: Internet
Author: User
When using Yii, the following situations occur: Use & amp; lt; ahref & quot; & amp; lt ;? Url: toRoute (& #039; sitelogout & #039 ;);? & Amp; gt; & quot; & amp; gt; exit the Background & amp; lt; a & amp; gt; after parsing, the URL of the code generated on the webpage is localhostyii2backendindex. php? Rsitelogout,... the following occurs when using Yii,
On the template page, use "> Exit the background
After parsing, the URL of the code generated on the webpage is localhost/yii2/backend/index. php? R = site/logout. The address is correct and the following occurs during access:
Method Not Allowed (#405) Method Not Allowed. This url can only handle the following request methods: POST. The above error occurred while the Web server was processing your request. Please contact us if you think this is a server error. Thank you.

Why is 405? Where is the configuration incorrect? No route is configured in the configuration file.
Firebug found that the front-end is acceptable, and it is POST submission. But is the access generated through the url incorrect? Help

Reply content:

When using Yii, the following situations occur,
On the template page, use"> Exit the background
After parsing, the URL of the code generated on the webpage is localhost/yii2/backend/index. php? R = site/logout. The address is correct and the following occurs during access:
Method Not Allowed (#405) Method Not Allowed. This url can only handle the following request methods: POST. The above error occurred while the Web server was processing your request. Please contact us if you think this is a server error. Thank you.

Why is 405? Where is the configuration incorrect? No route is configured in the configuration file.
Firebug found that the front-end is acceptable, and it is POST submission. But is the access generated through the url incorrect? Help

Configurationsite/logoutThe verbs of this action indicates that this action only accepts requests sent through POST!
Therefore, check whether behaviors under siteController is configured.

'verb' => [    'class' => VerbFilter::className(),    'actions' => [        'logout' => ['post'],    ],],

If GET access is allowed, you can change it:

'Verb' => ['class' => VerbFilter: className (), 'actions' => ['logout' => ['get'], // of course, it can be ['get', 'post'], and both post and get methods are supported],],

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.