duanfa2014 2018-08-03 17:35
浏览 1862

http.server - 不支持的方法('POST')

So I have created a website, when the user tries to fill out the login form (username and password), the following error message is displayed:

Error response
Error code: 501

Message: Unsupported method ('POST').

Error code explanation: HTTPStatus.NOT_IMPLEMENTED - Server does not support this operation.

For the server im using Python 3 http.server. To start the server i have a batch file containing the following code:

python -m http.server 80

I'm looking for a way to receive the login credentials the user submitted, and store them in a text file (.txt).

After doing some research I got the impression I need to create a PHP script, i have no idea how to do this. here is my attempt at it:

<?php
$username = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['password']);

echo $username, ' ', $password;
?>
  • 写回答

2条回答 默认 最新

  • doupai6875 2018-08-03 17:42
    关注

    https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/501

    It seems like you don't have POST support on your webserver. Try using GET instead.

    <?php
    $username = htmlspecialchars($_GET['username']);
    $password = htmlspecialchars($_GET['password']);
    
    echo $username, ' ', $password;
    ?>
    

    Although the code you wrote will simply print the user details, not store them. I would however recommend enabling POST and using it instead.

    Edit: As pointed out by another user GET is not secure and should not be used for passwords. This method will work but I would recommended not using it and instead looking for a way to implement POST into your webserver.

    I would also not recommend storing the passwords in a text file. PHP comes with built in methods for encrypting passwords. I would recommend reading about how to implement hashing such as Argon2:

    https://wiki.php.net/rfc/argon2_password_hash

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起