简体   繁体   English

未找到 VueJS POST 404

[英]VueJS POST 404 Not Found

My aim is to run my Quasar app to other devices connected to the Local Area Network.我的目标是将我的 Quasar 应用程序运行到连接到局域网的其他设备上。 I managed to run them as expected although, when I was logging in to the website, I am having this error POST http://10.0.0.20:8080/MyComposer/?submitId=3 404 (Not Found) despite working fine on my localhost before.我设法按预期运行它们,尽管当我登录网站时,我遇到此错误POST http://10.0.0.20:8080/MyComposer/?submitId=3 404 (Not Found)尽管我的工作正常本地主机之前。 Why is it not reading the Classes in my index.php at the backend folder properly?为什么它不能正确读取后端文件夹中我的 index.php 中的类?

PS I don't know if this could solve my problem but when I used phpinfo() to debug, I noticed that the REQUEST_METHOD there is GET instead of POST. PS 我不知道这是否可以解决我的问题,但是当我使用 phpinfo() 进行调试时,我注意到 REQUEST_METHOD 有 GET 而不是 POST。 Is it possible to swap them?可以交换它们吗? I'll try whatever you guys give me.我会尝试你们给我的任何东西。

Console安慰

General
Request URL: http://10.0.0.20:8080/MyComposer/?submitId=3
Request Method: POST
Status Code: 404 Not Found
Remote Address: 10.0.0.20:8080
Referrer Policy: no-referrer-when-downgrade

Response Headers
Connection: keep-alive
Content-Length: 151
Content-Security-Policy: default-src 'none'
Content-Type: text/html; charset=utf-8
Date: Tue, 28 Jul 2020 12:18:12 GMT
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Powered-By: Express

Request Headers
Accept: application/json, text/plain, 
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,es;q=0.8
Connection: keep-alive
Content-Length: 49
Content-Type: application/json
Host: 10.0.0.20:8080
Origin: http://10.0.0.20:8080
Referer: http://10.0.0.20:8080/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36

Headers.php头文件.php

<?php
header('Access-Control-Allow-Origin: http://10.0.0.20:8080/'); //OR EITHER http://10.0.0.20:8080/ OR .$_SERVER['HTTP_ORIGIN']
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Max-Age: 3600');
if (strtoupper($_SERVER['REQUEST_METHOD']) === 'OPTIONS') {
    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
        header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
        header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
    exit(0);
}

store.js store.js

   actions: {
      LOGIN (context, payload) {
        return new Promise((resolve, reject) => {
          axios
            .post('/MyComposer/', payload, {
              headers: { 'Content-Type': 'application/json' },
              params: {
                submitId: 3
              }
            })

index.php index.php

<?php
require 'Classes/Headers.php';
require 'vendor/autoload.php';

echo 'Hello!';
phpinfo();

use Classes\SubjectClass;
use Classes\TestClass;
use Classes\AnswerClass;
use Classes\LoginClass;
use Classes\RegisterClass;
use Classes\TeacherClass;
use Classes\StudentClass;
use Classes\AccountClass;
use Classes\AccessClass;
use Classes\SchoolClass;

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $addsubject = new SubjectClass();
    $addsubject->addSubject();
    $addtest = new TestClass();
    $addtest->addTest();
    $submitTest = new AnswerClass();
    $submitTest->submitTest();
    $submitLoginData = new LoginClass();
    $submitLoginData->submitLoginData();
    $addAccountData = new RegisterClass();
    $addAccountData->addAccountData();
    $addSchool = new SchoolClass();
    $addSchool->addSchool();
}

The problem was caused not by a coding error but due to two webservers being installed on the affected system, a XAMPP installation running on the default port 80 and a Node.Js server running on port 8080.该问题不是由编码错误引起的,而是由于受影响的系统上安装了两个 Web 服务器,一个 XAMPP 安装在默认端口 80 上运行,而 Node.Js 服务器在端口 8080 上运行。

To diagnose the problem we first copypasted the URL being used in the script into a browser window which gave the same 404 HTTP error.为了诊断问题,我们首先将脚本中使用的 URL 复制粘贴到浏览器 window 中,它给出了相同的 404 HTTP 错误。 This excluded the option that the axios.post() method caused the behavior.这排除了axios.post()方法导致该行为的选项。

Next the basic HTTP port assignment was tested.接下来测试基本的 HTTP 端口分配。 Calling the address http://10.0.0.20 (user's IP inside the local network) gave the correct XAMPP homepage.调用地址http://10.0.0.20 (本地网络内用户的 IP)给出了正确的 XAMPP 主页。 When checking the httpd.conf and in it the Listen setting (which should have been Listen 8080 ) we saw the Apache was using the default HTTP port isntead.在检查httpd.conf和其中的Listen设置(应该是Listen 8080 )时,我们看到 Apache 正在使用默认的 HTTP 端口。 Changing it to 8080 (as was used in the script) and restarting Apache resulted in the server not starting with the error:将其更改为 8080(在脚本中使用)并重新启动 Apache 导致服务器无法启动并出现以下错误:

Problem detected: Port 8080 in use by "C.\Program Files\nodejs\node.exe" with PID 3808!检测到问题:“C.\Program Files\nodejs\node.exe”正在使用端口 8080,PID 为 3808! Apache WILL NOT start without the configured ports free! Apache 不会在没有配置的端口空闲的情况下启动! You need to uninstall/disable/reconfigure the blocking application or reconfigure Apache and the Control Panel to listen on a different port.您需要卸载/禁用/重新配置阻塞应用程序或重新配置 Apache 和控制面板以侦听不同的端口。

It was now sure that messed up ports were the cause of the problem.现在可以确定是端口混乱是问题的原因。 Removing the :8080 from the scripts made sure the requests were sent to the right server.从脚本中删除:8080确保请求被发送到正确的服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM